Merge
Goal
- This project is about working with branches and how to merge changes of multiple branches into one again.
Hints
- Try to solve the following tasks with the help of the Slides and the Cheatsheets.
- If you still run into problems, you'll find an expandable hint block for every task with a detailed description of the solution.
Task 1
- Leave the repository
remote-branchesand create a new one:
cd .. # Leave the directory remote-branches
mkdir merge # Create a new directory merge
cd merge # Change into that directory
git init # Create a new Git repository
Solution (Click on the arrow if you are stuck)
- Leave the directory
remote-brancheswith the commandcd ... - Run the command
pwdand you should see/root/workspaceas a result. - If you got a different result, run
cd /root/workspaceto change into the right directory. - When you are in the right directory, run
mkdir merge. - Change into the newly created directory with
cd merge. - Run
git initwhich creates a new git repository in the current directory.
Task 2
- Create the following graph. Each commit/node should have the following properties:
- Node name = commit message
- Each commit (except merge commits) should create a file with the name of the commit message.
- Example: commit
C1creates a new fileC1.
Solution (Click on the arrow if you are stuck)
- Start with commit
C1. Create a new fileC1and commit that file with the messageC1. - In the graph, you can see that
C1has two successor commits. It is recommended to create a temporary branch, so you can come back to this commit later. Rungit branch branch1. You created a new branch namedbranch1. You are still on the branchmain. - Create the second commit
C2with a file calledC2. - For commit
C5you needC2andC3as predecessor. - Lets create commit
C3. For that, the previously created branchbranch1is useful. Change to that branch withgit switch branch1. You are now again on commitC1. Create the commitC3. - Change back on the branch
main. CreateC5with the commandgit merge branch1. This merges the changes of your currentmainbranch with the changes ofbranch1. While merging don't forget to adjust the message of the merge commit. - Rinse and repeat until the graph is complete.