Using git in VSCode

 

This is a short guide on how to use git in Visual Studio Code (VSCode). The purpose of git is to allow you to easily share your code with collaborators and track the changes each of you make.

Note: We assume you have already signed up for GitHub and installed git on your computer. Otherwise, see step 3 in this guide.

 

Cloning a repostiory


Ctrl+Shift+P + run git: clone + write link to repository (from e.g. step 1)

 

Working with a repostiory

 

  1. Open folder with repository (e.g. the one you just cloned in step 2)

  2. Download existing changes: Ctrl+Shift+P + run git: sync

  3. Make some changes, add/remove files, etc. (it does not matter whether it is done in VSCode, JypterLab or from your OS)

  4. Upload new changes:

    1. Ctrl+Shift+P + run git: commit all (choose "Always" if there is a pop-up)

    2. Write commit message

    3. Ctrl+Shift+P + run git: sync (choose "OK, don't show again" if there is a pop-up)

 

IMPORTANT NOTE: To avoid merge conflicts always download existing changes, before you make new ones. This reduces the risk of merge conflicts, where you and your collaborators have changed the same lines of code

 

4. Video guides for working with Git

  1. Victor and Christian create a repository and push their project to it here.

  2. A short explanation of important concepts and commands in Git, also found in L05, can be seen here.

  3. In this video, you'll see some examples of how to make additional commits across members to the project that Victor and Christian had uploaded. Also, solving merge conflicts.

 

5. Merge conflicts


Skip this if you are a first time user of git

If you get a merge conflict:

  1. Resolve conflicts by point-and-click (don't save the file)

  2. Ctrl+Shift+P + run git: stage all changes

  3. Ctrl+Shift+P + run git: commit all

  4. Ctrl+Shift+P + run git: sync

  5. Save the file

  6. Ctrl+Shift+P + run git: commit all

  7. Ctrl+Shift+P + run git: sync

 

Problems? You can undo last commit with git: undo last commit

Worst case: Make a new clone of the repository and redo the changes file-by-file.