git commands
git merge
Bring the commits from another branch into the current one.
git merge <branch>Angle brackets are yours to fill in. Windows, Linux, macOS.
Examples for git merge
Update your branch with the latest main
git merge origin/mainRun git fetch first, so origin/main is current. This brings main's new commits into your branch with a merge commit. To keep a straight history instead, rebase onto origin/main.
gittoolmergesubcommandorigin/mainas of your last fetchCancel a merge with conflicts
git merge --abortPuts the branch and the working tree back to how they were before the merge started. Changes you made while resolving conflicts are lost.
gittoolmergesubcommand--abortflagFinish a merge after fixing conflicts
git add <path> && git merge --continueStage each file once its conflict markers are gone, then continue. git commit does the same as --continue here.
gittooladdsubcommand<path>path&&pipegittoolmergesubcommand--continueflagMerge a branch as one commit
git merge --squash <branch>Stages every change from <branch> without committing. Commit once to get a single commit. Git does not record this as a merge, so git branch -d later says the branch is not merged; use -D.
gittoolmergesubcommand--squashflag<branch>argumentKeep a merge commit even when a fast-forward is possible
git merge --no-ff <branch>Without it, a branch with no divergence is merged by moving the pointer, and the history shows no sign that a branch existed. --no-ff keeps the branch visible as one unit.
gittoolmergesubcommand--no-ffflag<branch>argument
Flags
- --no-ff
- Always make a merge commit, even when git could just move the branch forward.
- --ff-only
- Merge only if git can move the branch forward. Stop instead of making a merge commit.
- --squash
- Stage all the branch's changes as one set, without committing or recording a merge.
- --abort
- Stop a merge that has conflicts and go back to where you were before it.
- --continue
- Finish a merge after you resolve and stage the conflicts.
- --strategy-option -X <option>
- Pass an option to the merge strategy, such as ours or theirs for conflicting hunks.