8.2. Version Control with Git

The objective of this chapter is to practice Version Control of a Modelica source code using Git. See also links to Git docss.

Based on http://swcarpentry.github.io/git-novice/

Slides: ETS Git slides.pdf, ETS Git slides.odp (LibreOffice),

Git spatial diagram: Git_spatial_diagram.pdf

8.2.1. Bash survival kit

The most useful commands:

  • pwd: Print Working Directory (answers the question “Where am I?”)

  • ls: List folder content (option -a to see all the content, including hidden files/folders)

  • cd: Change Directory (and cd .. to go to parent)

Extras:

  • rm: ReMove file(s)

  • mkdir: MaKe (create) a DIRectory

8.2.2. Personal work

Git commands: init, config, add, commit, diff, log

8.2.3. Publish work on GitLab

You should use the GitLab instance for teaching https://gitlab-student.centralesupelec.fr/.

You should not use those other GitLab instances:

Communicating with remotes: SSH versus HTTPS protocol

When cloning a repository or adding a remote, need to specify the URL (the “web address”) of the remote using one of those two schemes:

  • SSH URL (like git@gitlab-student.centralesupelec.fr:user/repo.git)

  • HTTPS URL (like https://gitlab-student.centralesupelec.fr/user/repo.git)

This chooses which internet protocol (SSH vs HTTPS) will be used for transfering commits between the local and the remote repository. Both choices are possible, but SSH requires some setup work (cf. doc setup SSH for GitLab: first create SSH keys and then add the public key to GitLab), whereas HTTPS can be used immediately.

So, unless you happen to be comforable with the SSH setup, I recommend using HTTPS. HTTPS requires inputting the login and password for each connection, but with Git for Windows, a Credential Manager is already setup to remember them after the first usage.

Managing stored Gitlab credentials under Windows

The Git Credential Manager for Windows conveniently remembers your login & password. However, it also remembers wrong ones! As a consequence, you will permanently get authentification errors like:

$ git pull
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab-student.centralesupelec.fr/user/repo.git/'

One solution is to dig into Windows’ Control Panel to edit those credentials where they are stored. The steps are (source: Accessing Credential Manager doc for Windows 10):

  1. To open Credential Manager, type “credential manager” in the search box on the taskbar and select Credential Manager Control panel.

  2. Select Windows Credentials to access the credentials you want to manage. In the list you should see the GitLab URL. You can erase or modify the entry.

8.2.4. Collaborative work

  1. Ping-pong workflow: an ideal collaboration with no conflict

  2. Managing conflicts