This section contains some instructions on using Git within VSCode. VSCode has its own guide on using Git, which you can find here. However, I don’t personally find it helpful, as much of it uses more advanced GitHub processes or GitHub Copilot. However, you are welcome to use it if you find it helpful!
Branches
A branch allows you to work on code without affecting the main project. If you are working on something more experimental, or are trying to debug something, it is best to do it on a different branch than main!
To check which branch you are working on, look in the lower left corner of your window. To the right of where it says "SSH: chios.cs.vt.edu" should be an icon that looks like a branching path. Whatever name is to the right of that is the name of the branch you are currently on.
To switch to a different branch, you can either use “git checkout [branch name]” or click on where it tells you the current branch you are on (see above), which opens a drop-down menu where the search bar shows the branches you have on your system.
To get a remote branch on your system, you can run “git checkout -b [branch name] origin/[branch name]” This will make a copy of the remote branch on your local machine. For more information, check out this tutorial (scroll about halfway down the page to “How to Git Checkout Remote Branch”)
To create a new branch, run “git checkout -b [newBranch]”
To push a change to main from a separate branch, do:
- git push origin [branch-name]
- git checkout main
- git pull
Pushing Changes
- Go to the left side of your VSCode window and push the branch icon (the third one from the top)
- You’re now in the source control window. You should see the files you’ve changed below the button that says “Commit”.
- If you want to discard your changes for a file, right click on the file and select "Discard Changes."
- If you are ready to commit your changes, you need to stage them. Move your cursor over each file you want to commit, then click the plus sign that appears. You can also right click on the file and select "Stage Changes."
- Enter a commit message describing the changes you're pushing. Some good things to note are what you added, what you removed, what effect, your changes have on the program, etc.
- Click the commit button to push your changes.
- The commit button should now change and say “Sync Changes.” Push this to ensure your changes are reflected in the GitLab Repository.