Git Cheat Sheet · Integrate
Merge a branch
git merge <branch>
git merge <branch> integrates another branch's commits into the current branch. If the current branch has not moved, Git simply moves it forward (fast-forward). Otherwise, it creates a merge commit that joins the two histories.
What it does
Integrates the commits of another branch into the current branch, with a merge commit if needed.
A use case
Your feature is finished and you want to integrate it into main.
On the command line
git switch main && git merge <branch>- Integrates the branch into main.
git merge --no-ff <branch>- Always creates a merge commit, to keep track of the branch.
git merge --ff-only <branch>- Only accepts a fast-forward.
git merge --squash <branch>- Groups all the changes into a single commit, which you make yourself.
git merge --abort- Abandons a merge in conflict.
In Merathon
- Switch to the receiving branch (main).
- Right-click the branch to integrate → "Merge <branch> into <current branch>".
- A specific commit can also be merged: right-click in the graph → "Merge this commit into…".
Frequently asked questions
What is the difference between merge and rebase?
A merge keeps history as it happened, with a merge commit. A rebase rewrites your commits on top of the other branch for a linear history.
How do I undo a merge already done?
Not pushed yet: git reset --hard ORIG_HEAD. Already pushed: git revert -m 1 <merge-commit>.