In this Chapter we will learn how to push LWC Files from Visual Studio to Github
Let’s Get Started !
1.Git : It is a distributed version control system. This tool is used to push files from local PC to Github or pull files from Github to local PC. Git can be run on terminal in windows or any other terminals (Eg: Gitbash)
2. GitRepository : It is place to store code or files and share it with others
Way 1 : We can create git repository (folder) in our local PC and can deploy it to the Github to share it
Step 1 : Install Git in your system (Link : https://git-scm.com/downloads)
Note : Open command prompt and type “git –version” to verify if git is installed
Step 2 : Create account on Github (Link : https://github.com/)
Step 3 : Create New Repository (Ex : DemoRepository) on Github and copy the URL (Note : Verify if git is installed in VS code) (Keep it public)
Copy the Remote Repository URL from Github
Step 4 : Verify if git is enabled in VS Code in settings
Click on the Gear icon in the bottom left in the VS code which opens the settings, type “git” and check if it is enabled in VS Code
Step 5 : Go to VS Code editor and Open the Folder/project
Step 6 : Click on Source Control Option in VS Code and Click on Initialize Repository to make the current project selected in VS initialized by Git
Step 7 : Once you click on “Initialize Repository” one folder is created in your project (.git)
Step 8 : You can see all the project files now under the Source Control and can see “U” at the end which means these files are untracked (Which means these files are not yet committed)
Step 9 : Give a Commit message(Ex : My First Commit) and Click on the Right mark to commit the changes (Every time we do commit, we need to type message)
Note : You get a message (“Would you like to automatically stage all your changes and commit them directly” with options.) I will select “yes” for now for this change
Step 10 : Your Source Control Folder will get empty
Note: Now Go to your Github repository which you created in earlier step
Step 11 : You can see in the below image that there are no project files in the github repository, as we have just “Committed” not “PUSH to Github”
Step 12 : Select “Terminal”
Run the below commands to upload your project files to Github
- git remote set-url origin https://github.com/Gyaneshwar-m/DemoRepository.git (github url)
- git push origin master
Note: origin = Remote repository branch
master = local repository branch
It means that we are pushing from master i.e. local branch to origin i.e. remote branch.
Output
Step 13 : Verify the uploaded files in the Github Repository
Way 2: Steps to create GitRepository local in your PC using Commands
- Open the cmd terminal, type “git init” in cmd and you can see inside the folder where you want to create your local repository
NOTE : One folder “.git” will be created
- Create one text file (First) in the repository folder
NOTE : git is still not tracking the text file
- Type “git status” and it shows that there is one file which is untracked
- To track the files, type “git add filename”
Ex : “git add First”
It is added to the git source code to track the file
- Type “git status” command , it says that there is a file which is tracked and which is staged to be committed
- Type “git commit” or with comment “git commit -m “File is committed to track the changes by Git”
- Type “ git log” to see the changes and the commit history
- Let us make changes to the file and see if it shows the changes. Make changes to file (First) and type “git status” to check the changes
Note : git shows that there are changes and not staged to commit
- To stage the changes type “git add filename” , the check the status once staged using the command “git status”
- Type “git commit -m “Changes should be tracked in git” use “git status” to check the status
Together we can learn faster
Join LWC study group on Telegram
Subscribe to Youtube channel and blog to get latest updates
Follow Gyaneshwar Malba on Twitter