Once you’ve set up a GitHub repository, you can share and pull changes from your teammates while keeping track of the history of your code. This code-sharing process involves pushing, pulling, and sometimes merging code, all of which are important concepts in git. This tutorial will provide instructions for using the git integration within the Visual Studio Code environment. If you are familiar with the command line git, you can use that instead.
Pushing Changes
Once you’ve made changes to your repository, you need to push them to the remote repository to save the current version history so your teammates can access them.
- Run
make clean
ormingw32-make clean
in the VS Code terminal to remove .o and .exe files - Select the Source Control view in VS Code on the left-hand menu bar, shown in Figure 1
- Stage your changes by selecting the “+” sign next to Changes
- Commit your changes
- Write a Git Commit Message (see the page on Git Commit Messages for tips on how to write a good commit message)
- Push your changes to the remote repository so your teammates can access them
VS Code may ask if you would like to periodically Fetch. Select Yes. This will avoid you from having to manually fetch changes from your teammates into your local repository.
- Check your GitHub repository- you should see the changes you just pushed!
Pulling Changes
If your teammates have pushed changes, you need to pull them into your local repository. To do this, navigate to the Source Control view, hover over the three dots, and click on Pull.
Make sure to always Pull before you commit your changes! This will help you avoid merge conflicts!
Managing Merge Conflicts
- Some files may be automatically merged
- Any files that contain conflicts will be marked in your directory of files, and conflicting sections will be marked with auto-generated in-code comments and highlighting in Visual Studio Code
- Manually review every file with conflicts and keep the changes you want, removing the auto-generated in-code comments
- Stage, commit, and push