Merge
You might say
The feature I built separately works. How do I bring it back into the main version?
Combine the commits from one branch into anotherMerge brings two lines of history together. Git can combine independent changes automatically, but overlapping edits may create conflicts that a person must resolve. Review the result and run tests after resolving, because a clean text merge can still break behavior.
When to use it
- Bring a reviewed feature into main
- Combine work from two branches
- Keep both lines of history
- Integrate a finished fix
When NOT to use it
- Resolve a conflict without understanding both sides
- Merge into the wrong target branch
- Assume no text conflict means no product conflict
- Mix unrelated cleanup into conflict resolution
Anatomy
<<<<<<< HEAD
Xiaoli's homepage
=======Xiaoli’s photography homepage
>>>>>>> feature/new-navStarting here is the conflict area, HEAD refers to the version of the branch you are currently on.
What does this line look like on the current branch? It is usually the content of the main line.
The boundary between the upper and lower versions must be deleted together when resolving the conflict.
What does this line look like on the merged branch?
The conflict area ends here, marking which branch the content comes from.
Variants
Fast-forward
Updating a3f9c21..e7b2d48
The target branch has no independent new commits
Merge Commit
Merge made by the 'ort' strategy.
There are new commits on both sides and the merge node needs to be retained
merge --abort
git merge --abort
When you need to abandon the current unfinished merge
Typical use cases
Feature integration
$ git switch main
Switched to branch 'main'
$ git merge feature/new-nav
Merge made by the 'ort' strategy.
index.html | 24 ++++++++++++++-----
1 file changed, 16 insertions(+), 8 deletions(-)
Pull request merge
Release preparation
Conflict resolution
Further reading