git Tutorial#

Here the usage of the git versioning system (add/commit/merge) is shown.

Best git practises for the course#

  1. The original code in the notebooks might be corrected or extended during the course. To minimize impact when merging changes we’ll create working copies of the notebooks. This also takes care that your notes are preserved which you might add into the notebooks.

  2. Before committing, these copies need to be added to the repository.

  3. Commit your changes regularly with meaningful commit messages. Do this in any case right before pulling new changes from upstream (our source repository).

Exercise 1: Create notebook copy, add and commit changes#

Make a working copy of this notebook#

Use the folder-view on the left and right-click on the git_tutorial.md-file and select Duplicate. Change the name to your liking. Now open that newly created notebook.

You can add any notes you like to this new notebook.

Add and commit changes#

Note: When committing changes the repository runs a set of pre-commit checks.

Open a terminal and add the following commands. Make sure you are in the root directory of the repository. Change the commit message to your liking.

user@hub:/$ git add docs/notebooks/lesson_00-introduction/git_tutorial-Copy1.md

Check the repo status:

user@hub:/$ git status

Commit your changes:

user@hub:/$ git commit -m "Add notes to git tutorial"

The pre-commit checks might fail. Just try adding/committing again, as the failures have been corrected during the checks.

Check the latest repo changes:

user@hub:/$ git log
[SS2025 74230b1] Add notes to git tutorial
 1 file changed, 95 insertions(+)
 create mode 100644 docs/notebooks/lesson_00-introduction/git_tutorial-Copy1.md

Exercise 2: Create new branch and add changes#

Save the current snapshot as separate branch#

user@hub:/$ git branch lesson_00

Change to created branch:#

user@hub:/$ git checkout lesson_00

make changes, add and commit#

You can make any changes to the notebooks in this feature branch. Try to add some additional notes to this notebook and add/commit them.

Exercise 3: merge changes from another branch#

Checkout source branch#

Now shutdown and close the notebook and run the following command.

user@hub:/$ git checkout SS2026

We can observe that our additional notes are not in this branch, but are preserved in the other branch. Try to switch back and forth, but shutdown/close the notebook before any switch.

Merge changes from other branch#

Changes in other branches can be merged:

user@hub:/$ git checkout SS2026
user@hub:/$ git merge lesson_00

Get changes from upstream#

When the upstream SS2026 branch has changed, these changes can be pulled in. Make sure you are on the SS2026 branch:

user@hub:/$ git checkout SS2026
user@hub:/$ git fetch
user@hub:/$ git pull

Learn more about git versioning#