You can use the git merge-base command to find the latest common commit between the two branches. If that commit is the same as your branch head, then the branch has been completely merged.
The more the branches and master diverge away from each other the farther away their “common ancestor” commit becomes. When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch.
The git branch command lets you create, list, rename, and delete branches. It doesn't let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.
To list branches with commits not merged into master:
git branch --no-merged master
To list the relevant commits:
git cherry -v master <branch>
I came across this question when I was trying to remember the syntax of...
git log <branch> --not master --stat
This will show commits to <branch> that have not been merged to master. The --stat will include the files that were changed with the commits. You can also use this to compare any two branches by replacing master with a different branch name.
This question is already well answered, but there is one more answer I think is worth documenting:
List all commits on any branch not already merged with master:
git log --all --not master
or, equivalently:
git log --all ^master
The --all
picks up all branches, so you don't have to list them, then --not master
or ^master
remove master from the selection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With