| Start |
| Merge one branch into another This merges the branch incomingBranch into the branch you are currently in. For example, if you are currently in master, then incomingBranch will be merged into master. Merging can create conflicts in some cases. If this happens, you will see the message Automatic merge failed; fix conflicts and then commit the result. You will need to manually edit the conflicted files, or to undo your merge attempt, run: |
| Automatic Merging When the commits on two branches don't conflict, Git can automatically merge them: |
| Aborting a merge After starting a merge, you might want to stop the merge and return everything to its pre-merge state. Use --abort: |
| Keep changes from only one side of a merge During a merge, you can pass --ours or --theirs to git checkout to take all changes for a file from one side or the other of a merge. |
| Merge with a commit Default behaviour is when the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. Use --no-ff to resolve. git merge <branch_name> --no-ff -m "<commit message>" |
| Finding all branches with no merged changes Sometimes you might have branches lying around that have already had their changes merged into master. This finds all branches that are not master that have no unique commits as compared to master. This is very useful for finding branches that were not deleted after the PR was merged into master. Syntax - git merge another_branch [options]
- git merge --abort
Parameters | Parameter | Details | -m | Message to be included in the merge commit | -v | Show verbose output | --abort | Attempt to revert all files back to their state | --ff-only | Aborts instantly when a merge-commit would be required | --no-ff | Forces creation of a merge-commit, even if it wasn't mandatory | --no-commit | Pretends the merge failed to allow inspection and tweaking of the result | --stat | Show a diffstat after merge completion | -n/--no-stat | Don't show the diffstat | --squash | Allows for a single commit on the current branch with the merged changes |
|