git,

List merged / unmerged branches in Git

Oct 10, 2022 · 1 min read · Post a comment

Here’s another nugget on how to list merged and unmerged Git branches. Personally, I don’t find it much useful, but who knows. Maybe you need to do a cleanup by removing every merged branch to main.

Prerequisites

  • Git

Solution

Merged branches

List all branches merged into main branch from both local and remote:

git branch -a --merged main

Local branches only:

git branch --merged main

Remote branches only:

git branch -r --merged main

Note(s): If you omit the branch main by default it will point to whatever HEAD points to, or simply put the tip of the current branch. Anyhow, you could specify another branch or even a commit ID.

Unmerged branches

List all branches that are not merged yet into main from both local and remote:

git branch -a --no-merged main

Local branches only:

git branch --no-merged main

Remote branches only:

git branch -r --no-merged main

Note(s): As with the --merged parameter, the same goes with this one. You have the option to specify a commit ID or another branch as well.

Conclusion

To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.

git