This Guide will elaborate on teamwork in git and using branches.
After reading this guide, you will know:
Slides - use arrow keys to navigate, esc to return to page view, f for fullscreen
Every commit is just a small change that points to the commit before.
A branch is just a pointer to a certain commit.
If you create a branch called a3
and add
a few commits W, X, Y, and Z to it, it might look like this:
If you merge back into main now everything will be fine.
But what if the main branch moves on?
Let's say three other commits are added to the main: B, C and D:
If you merge this, the merge might get complicated. A new Commit is created that contains all the necessary changes:
But there's a better approach: First you rebase your branch onto the main:
git checkout a3
git rebase main
This will try to apply the new commits in a4 on top of the current state of main, leading to this situation:
After the rebase a merge into main will be simple.
When working with feature branches you try to merge as fast as possible.
But if the main branch moves on while you are working on your feature,
you can use git rebase
to catch up:
git fetch
git checkout a3
git pull origin a3
git rebase main
# fix problems, run test, fix problems again
git push -f origin a3 # overwrite branch with rebased branch
# work on your merge request