Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
380049c
revise exercise 1
AnnikaLau Feb 11, 2026
7f36541
Ex 1: Make everything crystal clear and format admonitions
mjaehn Feb 16, 2026
bf2978d
Merge branch 'review_beginner' of github.com:C2SM/git-course into rev…
mjaehn Feb 16, 2026
aaad8c7
Fix admonitions
mjaehn Feb 16, 2026
86aa39e
Ex 1: Fix formatting
mjaehn Feb 16, 2026
159f30d
Ex 1: Use proper headings
mjaehn Feb 16, 2026
193d3ab
Make sed commands work on different systems
AnnikaLau Feb 16, 2026
d582d1d
revision Exercise 5
AnnikaLau Feb 17, 2026
6262129
revise exercise 4
AnnikaLau Feb 17, 2026
6c0d0e1
Python only needed for advanced
AnnikaLau Feb 19, 2026
7a1ba5e
Fix sentence
AnnikaLau Feb 19, 2026
359920d
Improved notes/admonitions
stelliom Mar 11, 2026
154453a
Made it even more clear that <> should be removed
stelliom Mar 11, 2026
91da43f
Reviewed exercise 2
stelliom Mar 11, 2026
5612a09
Reviewed exercise 6
stelliom Mar 12, 2026
2330b02
Reviewed exercise 7
stelliom Mar 12, 2026
6a14150
Improve remaining admonitions
stelliom Mar 12, 2026
94e5338
Small fix
stelliom Mar 12, 2026
b52acd0
Use code font for git commands
stelliom Mar 12, 2026
ba35fff
Omit Python check for beginners course
mjaehn Mar 13, 2026
7a5ba95
Ex 2: Fix tip admonition
mjaehn Mar 13, 2026
c47d5f3
Revise Ex. 3
mjaehn Mar 13, 2026
170c4a6
Ex 3: fix section title
mjaehn Mar 13, 2026
0551b01
Ex. 3: Write out sections in files
mjaehn Mar 13, 2026
dda9f22
Ex. 3: Improve language and fix typos
mjaehn Mar 13, 2026
a23059d
Ex. 4: Improve formatting and language
mjaehn Mar 13, 2026
6a0c4a6
Ex. 5: Add explainations to remote branches
mjaehn Mar 13, 2026
37d3aa8
Ex. 6: Fix output
mjaehn Mar 13, 2026
42f946c
Ex 6: Improve language and formatting
mjaehn Mar 13, 2026
8e4c0b0
Small cosmetic fix
stelliom Mar 13, 2026
256cac6
Apply suggestion from @AnnikaLau
mjaehn Mar 13, 2026
54529c7
Apply suggestions from code review
mjaehn Mar 13, 2026
a527a4c
Merge branch 'main' into review_beginner
AnnikaLau Mar 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The folder [advanced](advanced) contains the exercises for the C2SM Git Workshop
To run this course on your computer, the following things need to be set up:
1. [Git](#1-installing-git-on-your-computer)
2. [SSH key linked to your GitHub account](#2-creating-a-github-account-and-ssh-key)
3. [Python](#3-installing-python)
3. [Python](#3-installing-python) (only advanced)
4. [Final check](#4-final-check)


Expand Down Expand Up @@ -72,8 +72,22 @@ curl -O https://raw.githubusercontent.com/C2SM/git-course/main/check_requirement
chmod +x ./check_requirements.sh
```
- Step 3: Run the script from a Linux shell.

#### Beginners Course

For the Beginners course, Python is not required for the exercises in the _beginner_ folder.

```
./check_requirements.sh --beginner
```

#### Advanced Course
For the Advanced course, there is an additional check if Python is installed.

```
./check_requirements.sh
```

If the check is successful, everything is set up correctly.

**Have fun!**
71 changes: 45 additions & 26 deletions beginner/Exercise_1_basic_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,45 @@ For this exercise, we will use the following functions from this file:

## Remarks

> **Note:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word.
> [!NOTE]
> Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word/sentence.

> **Note:** Some exercises may require the use of basic Unix commands. If you are unfamiliar with Unix systems, refer to the file [Basic Unix Commands](../Unix_Commands.md) for a list of all necessary commands.
> [!TIP]
> Some exercises may require the use of basic Unix commands. If you are unfamiliar with Unix systems, refer to the file [Basic Unix Commands](../Unix_Commands.md) for a list of all necessary commands.

## Global Git Configuration Settings

Before we start using Git, we should set some global configurations. This only needs to be done once, and will be saved for all your future sessions.

1. First of all, we need to tell Git who we are.
To do this, run the following lines with your credentials:
### 1. Set User Credentials

First of all, we need to tell Git who we are. To do this, run the following lines and replace your name and email address
between the quotes ("") with your credentials:

> [!NOTE]
> Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word/sentence.

```
git config --global user.name "<John Doe>"
git config --global user.email "<my_name@some.domain>"
```
> **Note:** Use your real first and last name as your username and set the same email as your GitHub account. Also, ensure your actual name is set on GitHub; otherwise, your commits will appear under different authors.

At the end of this course, you will learn something about repository managers like GitHub. Recently, they changed their naming policy for the initial branch from *master* to *main*. So we want to tell Git to set our default branch name to *main* as well.
> [!IMPORTANT]
> Use your real first and last name as your username, and use the same email address as you have on your GitHub account. Also, make sure that your real name is set on GitHub; otherwise, your commits will appear under different authors.

At the end of this course, you will learn something about repository managers like GitHub.

> **Note:** Refer to the official Git documentation (https://git-scm.com/docs/git-init#Documentation/git-init.txt--bltbranch-namegt).

2. Set *main* as the default branch name:
### 2. Set *main* as the default branch name:

Recently, they changed their naming policy for the initial branch from *master* to *main*. So we want to tell Git to set our default branch name to *main* as well.

```bash
git config --global init.defaultBranch main
```

> [!TIP]
> Refer to the official Git documentation (https://git-scm.com/docs/git-init#Documentation/git-init.txt--bltbranch-namegt).

## Clone the `git-course` Repository

Expand All @@ -69,7 +84,8 @@ If you are satisfied with your current directory, use the following command to c
git clone git@github.com:C2SM/git-course.git
```

> **Note:** If you did not set up an SSH key linked to your GitHub account, you will have to use `https://github.com/C2SM/git-course.git` instead for cloning the repository.
> [!IMPORTANT]
> If you did not set up an SSH key linked to your GitHub account, you will have to use `https://github.com/C2SM/git-course.git` instead for cloning the repository.

You can now navigate into it with

Expand All @@ -87,7 +103,8 @@ cd beginner

---

> **To initialize the exercise properly, run this code at the very beginning. Check the [Helper Functions](#helper-functions) section above for more explanation.**
> [!IMPORTANT]
> To initialize the exercise properly, run this code at the very beginning. Check the [Helper Functions](#helper-functions) section above for more explanation.

```bash
# source the helpers.sh file to be able to use its functions
Expand All @@ -103,19 +120,20 @@ repository! You can check this with the `pwd` command.

### Optional: restart exercise repo

⚠️ **In case you messed up somehow, execute the `reset` function. Check the [Helper Functions](#helper-functions) section above for more explanation.**

```bash
## only execute this in case of (serious) trouble ##
## it will delete your entire beginners_git directory ##
reset
```
> [!IMPORTANT]
> **In case you messed up somehow, execute the `reset` function. Check the [Helper Functions](#helper-functions) section above for more explanation.**
>
>```bash
>## only execute this in case of (serious) trouble ##
>## it will delete your entire beginners_git directory ##
>reset
>```

## Exercise


### Create a Git repository from scratch
> Hint: check the [Basic Unix Commands](../Unix_Commands.md) if you don't know how to do the following.
> [!TIP]
> Check the [Basic Unix Commands](../Unix_Commands.md) if you don't know how to do the following.

1. Create a new folder (e.g. *git_repo*) and navigate to it
2. Use the command `git init` to initiate your first Git repository
Expand All @@ -139,7 +157,6 @@ echo "<my text for file>" > first_file.txt

You should now get an output similar to:


```
On branch main

Expand Down Expand Up @@ -178,6 +195,10 @@ Changes to be committed:
```

6. The last thing to do is to commit these files together with a commit message:

> [!NOTE]
> Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word/sentence.

```bash
git commit -m "<meaningful message>"
```
Expand Down Expand Up @@ -229,15 +250,13 @@ The "+" indicates that we have a new line in our file.

Let's modify the second file as well.

4. Add a new line in the second file

The next lecture is starting soon, so let's add and commit our changes for safety reasons.
4. Add a new line in the second file.

5. Add the two modified files with `git add`
5. Add the two modified files with `git add <file name>`.

6. Use `git status` to check if your action was successful
6. Use `git status` to check if your action was successful.

7. Now commit your changes with a meaningful commit message
7. Now commit your changes with a meaningful commit message.

**Congrats!**
But how many commits do you already have in this repository?
Expand Down
17 changes: 12 additions & 5 deletions beginner/Exercise_2_switch_branches.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Objective

* Learn how to work with branches and switch between them using `git switch`.
> **Note**: `git checkout` can be used as an alternative to `git switch`. However, it has different features that have caused confusion among users in the past. So we won't use it here, but show the alternative commands in brackets, as some older Git versions don't have this option yet.
> [!NOTE]
> `git checkout` can be used as an alternative to `git switch`. However, it has different features that have caused confusion among users in the past. So we won't use it here, but show the alternative commands in brackets, as some older Git versions don't have this option yet.

## Structure

Expand All @@ -21,9 +22,11 @@ For this exercise, we will use the following functions from this file:

## Remarks

> **Note:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word.
> [!NOTE]
> Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word/sentence.

> **Note:** Some exercises may require the use of basic Unix commands. If you are unfamiliar with Unix systems, refer to the file [Basic Unix Commands](../Unix_Commands.md) for a list of all necessary commands.
> [!TIP]
> Some exercises may require the use of basic Unix commands. If you are unfamiliar with Unix systems, refer to the file [Basic Unix Commands](../Unix_Commands.md) for a list of all necessary commands.

If everything is still set up from the last exercise, you can continue with [this exercise](#exercise) directly.
Otherwise, please refer to the [Initialization from Exercise 1](Exercise_1_basic_commands.md#initialization).
Expand Down Expand Up @@ -55,6 +58,10 @@ To keep things organized, we will do this in two different Git branches, one for

**Let's get started!**
1. Create a new branch for planning day 1:

> [!NOTE]
> Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word/sentence.

```bash
git switch -c <meaningful_branch_name_A>
# (Alternative: "git checkout -b <meaningful_branch_name_A>")
Expand All @@ -79,14 +86,14 @@ no changes added to commit (use "git add" and/or "git commit -a")

For the planning of the other day, we want to use another Git branch.
To keep track of all the different branches, Git provides the `git branch` command to see all branches of a repository.
The * indicates our current branch. Hit the `q` key to exit the branch view.
The `*` indicates our current branch. If a branch view has been opened, you can close it with by pressing the `q` key.

```bash
git branch
```

We can easily switch between these branches using the `git switch` command.
Don't worry -> Git will keep all your committed work on that branch.
Don't worry -> Git will keep all your **committed** work on that branch.

5. Switch back to *main* branch:
```bash
Expand Down
73 changes: 32 additions & 41 deletions beginner/Exercise_3_restore_merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ For this exercise, we will use the following functions from this file:

## Remarks

> **Note:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word.
> [!NOTE]
> Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word/sentence.

> **Note:** Some exercises may require the use of basic Unix commands. If you are unfamiliar with Unix systems, refer to the file [Basic Unix Commands](../Unix_Commands.md) for a list of all necessary commands.
> [!TIP]
> Some exercises may require the use of basic Unix commands. If you are unfamiliar with Unix systems, refer to the file [Basic Unix Commands](../Unix_Commands.md) for a list of all necessary commands.

If everything is still set up from the last exercise, you can continue with [this exercise](#exercise) directly.
Otherwise, please refer to the [Initialization from Exercise 1](Exercise_1_basic_commands.md#initialization).
Expand Down Expand Up @@ -51,10 +53,10 @@ To avoid doing the same work twice, we want to reuse the old schedules that we d

We can use `git restore` to get any version of a file along its Git history.

Just run `git restore -s <specific_commit_hash> <your_schedule>`.
Just run `git restore -s <specific_commit_hash> <your_file(s)>`.

> **Note**:
For simplicity, we've used the `-s` option in the `git restore` command. Note that `-s` is a shorthand for `--source`, which you can also use interchangeably. The primary difference lies in the syntax: use `-s <commit_hash>` for a shorter command, or `--source=<commit_hash>` if you prefer a more explicit approach. Both options perform the same function: specifying the source from which to restore. Whether you prefer `-s` for brevity or `--source` for clarity is up to you.
> [!NOTE]
> For simplicity, we've used the `-s` option in the `git restore` command. Note that `-s` is a shorthand for `--source`, which you can also use interchangeably. The primary difference lies in the syntax: use `-s <commit_hash>` for a shorter command, or `--source=<commit_hash>` if you prefer a more explicit approach. Both options perform the same function: specifying the source from which to restore. Whether you prefer `-s` for brevity or `--source` for clarity is up to you.

2. Undo "Change poster sessions to talks" by restoring the *schedule_day1.txt* to the commit before the change.

Expand All @@ -81,7 +83,7 @@ Your output should look similar to:
b7bd111 (HEAD -> main) Remove workshop on day 1
f6c3f04 Change talks back to poster sessions
5889296 Change poster sessions to talks
464fc92 Add workshop
464fc92 Add workshops
e53b1e0 Add coffee break
f1b23c1 Add poster sessions in the morning
f636890 Add schedule_day2
Expand All @@ -94,75 +96,64 @@ In this part of the exercise, we will continue working on *schedule_day1.txt*.
There are two sections in *schedule_day1.txt*, which we will change on separate branches:
* *daily_program*
* *evening_activity*

> **Note**: Try to avoid merge conflicts by not changing the same part of a file in two branches you want to merge (usually the *main* branch and a branch you want to merge into the *main* branch). There are, of course, ways to deal with merge conflicts, and we will learn how to deal with them later in this course, but for now we will try to avoid them. If you follow the descriptions below, you should not run into a merge conflict.

1. Switch to a new branch for the evening activity.
#### Preparing your branches
1. Create and switch to a new branch for the evening activity.

2. Open the schedules and add evening activities.
2. Open *schedule_day1.txt* and add evening activities only in the "Evening activity" section (e.g., add a dinner or social event).

3. Add and commit the changes.

4. Go back to the *main* branch using `git switch` (if you don't go back to the *main* branch but create a new branch, it will be based on the current branch and not the *main* branch).
4. Switch back to the *main* branch.

5. Now create another branch to add more to the daily program. Add at least one more event to the daily program.
5. Create another branch to add more to the daily program.

6. Add and commit your changes
6. Open *schedule_day1.txt* and add at least one more event only in the "Daily program" section (e.g., add a new talk or session).

7. Now switch back to branch *main* and run `git branch`
7. Add and commit your changes.

The output should look like:
```
8. Switch back to the *main* branch. Check your branches; they should look like this:

```bash
daily_program
evening_activity
* main
daily_program
```

Let's put the pieces of the schedules together. For that we use the `git merge` functionality.
It allows us to merge files with different text from different branches.


To merge all modifications from a branch into the current branch, we type `git merge <branch-to-be-merged>`

8. Merge evening activity into the *main* branch (make sure you are on the main branch for that).

Git just performed a so-called **fast-forward merge**. This means that there is a linear path
between the two merged branches. See the slides for more detailed information about it.

**Most important:**
Git does **NOT** create an additional commit to perform the merge. It only appends the commit from the branch *evening_activity* to the HEAD.
#### Fast-forward merge

9. Check Git history to see the added commit.
9. Merge the *evening_activity* branch into *main*. To merge all modifications from a branch into the current branch, type `git merge <branch-to-be-merged>`.

Check the contents of the schedules.
10. Check the history of your *main* branch. It should now include the commit from the *evening_activity* branch.

As you can see, we successfully merged our changes from the *evening_activity* branch into the *main* branch. After merging a branch, it is always good practice to delete it.
11. It is good practice to delete branches that have already been merged: `git branch -d <branch-to-be-deleted>`.

10. Delete the branch for the evening activities with `git branch -d <evening activities branch>`.
#### 3-way merge

Let's do the same, but for the changes in the branch for the daily program.
In your branch for the evening activity, you only changed the "Evening activity" section in your file. In the branch for daily program, you only changed the "Daily program" section, respectively. This will ensure a merge without a merge conflict in the end.

11. Merge the branch for the daily program into the *main* branch.
Since you merged *evening_activity* into *main*, the *main* branch now has a diverging history compared to the *daily_program* branch.
Therefore, when you merge *daily_program* into *main*, Git will create a merge commit (3-way merge).

For this merge, Git performs what is called a **3-way merge**, because the path between the two branches is no longer linear due to the merge of the branch for planning the evening activities. So Git creates a **merge commit** to merge the two histories together.
12. Merge the *daily_program* branch into *main*. This time, you need to set a commit message: `git merge <branch_name> -m "Merge daily_program"`

12. Take a look at the schedules and see what they look like. Then check out the new history of your current branch.
13. Check the history and the contents of the schedules. The *main* branch should now contain both sets of changes: daily program and evening activity.

Your Git log looks like the following:
Your Git log should look like this:
```
c0d0459 (HEAD -> main) Merge daily_program
b1be3b4 (daily_program) Add talks
4d93eac Add evening activities
b7bd111 Remove workshop on day 1
f6c3f04 Change talks back to poster sessions
5889296 Change poster sessions to talks
464fc92 Add workshop
464fc92 Add workshops
e53b1e0 Add coffee break
f1b23c1 Add poster sessions in the morning
f636890 Add schedule_day2
206f724 Add schedule_day1
```

13. Again, make sure to delete the branch you just merged.
14. Delete the branch you just merged.

**Congrats, your Git skills are getting better and better!**
Loading