Skip to content
Snippets Groups Projects
Commit 2ca5fbca authored by Tobias Schlauch's avatar Tobias Schlauch
Browse files

Add initial episode content

parent f288abca
No related branches found
No related tags found
1 merge request!1Resolve "Rework episode 9 (conflicts)"
......@@ -7,9 +7,21 @@ SPDX-License-Identifier: CC-BY-4.0
# Conflicts
In this episode, we create [a conflict](https://swcarpentry.github.io/git-novice/fig/conflict.svg) and resolve it.
In addition, we briefly introduce the typically used concepts of `branching` and `merging`.
Please see [the original Conflict episode](https://swcarpentry.github.io/git-novice/09-conflict/index.html) for further details.
In addition, [conflicts.pptx](extras/conflicts.pptx) shows an animation of all performed
steps.
In addition, [conflicts.pptx](extras/conflicts.pptx) shows an animation of all performed steps.
## Background
- `Branching` is an important concept in Git.
- A `branch` is a specific series of commits of the repository.
- The `master` branch reflects the current state / "truth" of the repository and typically acts as synchronization point for starting off new work and re-integrating finished work.
- Every Git repository can contain as many branches as you want.
- Every Git repository can have different branches.
- Branches can be shared between Git repositories.
- Typically, you start a new piece of work by creating a new `branch` out of the `master` branch.
- Once, you are finished with your work you re-integrate it by `merging` your working branch back into the `master` branch.
- When re-integrating your work, it might happen that `conflicts` occur because someone else changed the same lines as you.
## Configure some Useful Details
......@@ -18,28 +30,66 @@ steps.
- View diff while writing commit message `git config --global commit.verbose true`
- Test with `git config --global --edit`
## Create a Conflict
## Create a new Branch and start your Work
- Show the existing branches
- `git branch --all`
- Explain the labels `master` and `HEAD`
- Explain remote and local branches
- Show graph of the repository
- Draw state of the repository
- Verify with `git graph`
```
o - o <- HEAD, master
```
- Create a new branches
- `git branch mumy-info`
- Show what changed
- Verify with `git branch` and `git graph`
- Explain that `*` marks where the HEAD is pointing to
```
o - o <- HEAD, master, mummy-info
```
- Switch to the newly created branch
- `git checkout mummy-info` (Git version >= 2.23 supports: `git switch <BRANCH NAME>`)
- Verify with `git graph`
- Edit the file `mars.txt` and commit the changes
- Add a new sentence at the end of the file: `Mummy will appreciate sand storms on Mars`
- Add & commit it: `git add mars.txt`, `git commit -m "Add advantages for the Mummy"`
- Verify with `git branch` and `git graph`
```
o <- HEAD, mummy-info
/
o - o <- master
```
## Prepare the Conflict
- Switch back to the `master` branch
- `git checkout master` (Git version >= 2.23 supports: `git switch <BRANCH NAME>`)
- Verify with `git graph`
- Edit the file `mars.txt` and commit the changes
- Add a new sentence at the end of the file: `Generating solar energy is less effective on Mars`
- Add & commit it: `git add mars.txt`, `git commit -m "Add information about energy generation"`
- Verify with `git branch` and `git graph`
```
o <- mummy-info
/
o - o - o <- HEAD, master
```
- In the remote repository:
- Change the sentence on first line to `Cold, dry and rocky, but everything is my favorite color` in `mars.txt`
- Add a new sentence: `Mummy will appreciate sand storms on Mars` to `mars.txt`
- Commit the changes with the commit message `"Prepare merge conflict on GitLab"`
- Show GitLab's `/commits` or `/graph` pages
- In the local repository:
- Add a new sentence: `Generating solar energy is less effective on Mars` to `mars.txt`
- Add & commit it: `git add mars.txt` & `git commit -m "Prepare merge conflict locally"`
- Show local commit log:
- `git graph`
- Show that a push to remote fails:
- `git push origin master`
- Explain reasons
- Optional: `git fetch -v`
## Resolve the Conflict
- Pull from remote repository:
- `git pull`
- Perform manual merge with the editor by editing the `<<< ... === ... >>>` section and removal of these conflict markers
- Merge the working branch (`mummy-info`) into the `master`branch
- `git merge mummy-info`
- Explain the output and the consequences
- Resolve the conflict manually with the help of the editor by editing the `<<< ... === ... >>>` section and removing the conflict markers
- Mark the conflict as resolved:
- `git add mars.txt`
- `git commit` (without commit message => explain interactive commit with default message)
......@@ -47,12 +97,12 @@ steps.
- `git graph`
- Highlight the split with coexisting commits
- Highlight that no version/commit is lost in a merge
- Highlight that `origin/master` is behind `master` (local Git repository)
- Push result to remote repository:
- `git push`
- Show local commit log:
- `git graph`
- Highlight that `origin/master` and `master` (local Git repository) are equal
```
o <- mummy-info
/ \
o - o - o - o <- HEAD, master
```
## Key Points
......
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