Skip to content
Snippets Groups Projects
Verified Commit 11372990 authored by Lukas Kluft's avatar Lukas Kluft
Browse files

Restructuring of branches sections

* Add mermaid graphs to illustrate different branching schemes
* Move rebasing to backup slides
* Make the conflict example more verbose
parent eb0a69c4
No related branches found
No related tags found
No related merge requests found
......@@ -52,103 +52,188 @@ git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
```
## Hands-on Session! {background-color=var(--dark-bg-color)}
## Hands-on Ssssion {background-color=var(--dark-bg-color)}
1. Configure the username and email adress in your local git client
2. Initialize an empty Git repository
3. Create a file and add it to the repo
3. Change the file, inspect the differences, and commit the changes
# Branches
:::info
On Levante: `module load git`
:::
# Branches
::: {.incremental}
* Are versions of the code identified with a name (besides the existing hash)
* Are used to encapsulate the changes required for a feature/bugfix
* Are used to encapsulate the changes required for a feature/bugfix
* Allow incremental development without impacting the other branches
:::
## Branch operations
```bash
git branch b1 # create branch
git checkout b1 # switch to the new branch
## Create a branch
git branch -m b2 # rename a branch
Create a branch `develop` to work on a feature
git branch # check branches
```bash
git branch develop
git switch develop
```
git diff b1..b2 # compare branches
```{mermaid}
gitGraph
commit
commit
branch develop
checkout develop
commit
commit
```
git branch -d b1 # delete branch
::: {.fragment fragment-index=0}
Show differences between two branches
```bash
git diff develop..main
```
:::
## Merge a branch
## Merge a branch
TODO add drawing !
Merge the commits of `develop` into `main`
```bash
git checkout master
git merge b1 # merge branch b1 into master
```bash
git checkout main
git merge develop
```
```{mermaid}
gitGraph
commit
commit
branch develop
checkout develop
commit
commit
checkout main
merge develop
```
## Hands-on Session! {background-color=var(--dark-bg-color)}
## Hands-on session {background-color=var(--dark-bg-color)}
1. Create a branch
2. Rename the branches
3. Commit something in the branch
4. Merge the new branch on master
5. Check the log for the master branch
6. Delete the new branch
3. Commit something in the branch
4. Merge the new branch
5. Check the log for the `main` branch
6. Delete the new branch (`git branch --help`)
# Rebase a branch
TODO add drawing
- what does it do
## Conflicts
In collaborative developments people may disagree
```bash
git rebase master
```
## Hands-on Session! {background-color=var(--dark-bg-color) .leftalign}
:::: {.columns}
1. Create `file.txt` in two different branches with this content:
::: {.column width="30%"}
```{mermaid}
gitGraph
commit
commit
branch alice
checkout alice
commit
checkout main
branch bob
checkout bob
commit
```
:::: {.columns}
:::
::: {.column width="50%"}
::: {.column width="70%"}
::: {.fragment fragment-index=0}
Alice fixes an obvious error `file.txt`
```bash
# master branch
echo "Text in master" > file.txt
```{diff}
-This course is lame
+This course is nice!
```
:::
::: {.column width="50%"}
::: {.fragment fragment-index=1}
Bob is doing the same
```bash
# branch b1
echo "Text in branch" > file.txt
```{diff}
-This course is lame
+This course is awesome!
```
:::
:::
::::
2. Rebase branch b1 on master
```bash
git rebase master
## Conflicts
This will create a conflict when trying to merge both branches
```{mermaid}
gitGraph
commit
commit
branch alice
checkout alice
commit
checkout main
branch bob
checkout bob
commit
checkout main
merge alice
merge bob
```
3. Edit conflicts
```bash
```{raw}
Auto-merging file.txt
CONFLICT (content): Merge conflict in test.txt
Recorded preimage for 'file.txt'
Automatic merge failed; fix conflicts and then commit the result.
```
## Solving conflicts {auto-animate=true}
Solving conflicts requires **your decision**
```{.raw filename=file.txt}
<<<<<<< HEAD
This course is nice!
=======
This course is awesome!
>>>>>>> bob
```
## Solving conflicts {auto-animate=true visibility="uncounted"}
Solving conflicts requires **your decision**
```{.raw filename=file.txt}
This course is awesome!
```
:::{.fragment}
After resolving the conflict, you have to commit your changes
```{sh}
git add file.txt
git rebase --continue
git commit
```
:::
## Hands-on session {background-color=var(--dark-bg-color) .leftalign}
1. Create `file.txt` in two different branches with different content
2. Merge both branches into `main` (CONFLICT!)
3. Resolve the conflict and commit your changes
# Best practices
......@@ -205,7 +290,7 @@ git merge
- ...
## Hands-on Session! {background-color=var(--dark-bg-color) .leftalign}
## Hands-on session {background-color=var(--dark-bg-color) .leftalign}
1. Push your repository to GitLab
2. Add your ssh key to the repository
......@@ -213,7 +298,7 @@ git merge
4. Create a merge request (add author, reviewer, ...)
5. Approve and merge it to main
# Take-home messages!
# Take home messages
* You should use git daily!
* Industry is using it as de facto standard
......@@ -221,7 +306,43 @@ git merge
# Shotgun buffet
##
* useful tools for merge: vscode, meld
* on Levante: `module load git`
* documentation links
\ No newline at end of file
## Rebase vs merge
Instead of merging branches, one can also [rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing)
:::: {.columns}
::: {.column width="50%"}
```{mermaid}
%%{init: {'gitGraph': {'showCommitLabel': false}} }%%
gitGraph
commit
commit
branch develop
checkout develop
commit
commit
checkout main
commit
```
:::
::: {.column width="50%"}
```{mermaid}
%%{init: {'gitGraph': {'showCommitLabel': false}} }%%
gitGraph
commit
commit
commit
branch develop
checkout develop
commit
commit
```
:::
::::
Rebasing retains a linear history by **changing the commit history (!!!)**
## Useful tools for merge: vscode, meld
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment