git merge
Bring the changes from another branch into the current one
What it does
git merge brings the commits of the branch you name into the current branch. Usually you first switch to the branch you merge into (say, main) and run git merge there with the name of the task branch.
If the current branch has not moved since, git simply moves it forward (fast-forward). If both have changed, git creates a merge commit. When the same lines were changed differently in both branches, you get a conflict: git marks those places in the files, you fix them by hand, stage them with git add and finish the merge with git commit. git merge --abort cancels the merge and puts everything back.
Syntax
git merge <branch>
git merge --abortExamples
Merge the feature/login branch into the current one
git merge feature/loginmerge— join another branch’s history into the current onefeature/login— which branch
Related commands
- git rebase — Move a branch's commits onto a new base, or rewrite the last commits
- git switch — Switch to another branch, or create a new one and switch to it
- git pull — Download changes from the server and merge them into the current branch