Git bits 2
Contents
Using the Scala source repo to demonstrate - see Github
Show merged and unmerged branches
This command allows you to show all local branches merged / unmerged to current branch
➜ scala git:(2.12.x) git branch -a --merged
* 2.12.x
remotes/origin/2.11.x
remotes/origin/2.12.x
remotes/origin/HEAD -> origin/2.12.x
➜ scala git:(2.12.x) git branch -a --no-merged
remotes/origin/2.10.x
remotes/origin/2.8.x
remotes/origin/2.9.x
remotes/origin/DarkDimius-patch-1
remotes/origin/gh-pages
remotes/origin/legacy/msil
This shows you all local branches merged into named branch:
➜ scala git:(2.12.x) git branch -a --merged origin/2.9.x
remotes/origin/2.9.x
Better output
Put these 2 lines into ~/.gitconfig under the ‘[alias]’ section
unmerged = !git branch -r --no-merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'%Cgreen%d%Creset | %h | %an | %Cblue%ar%Creset' -1 | column -t -s '|'
merged = !git branch -r --merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'%Cgreen%d%Creset | %h | %an | %Cblue%ar%Creset' -1 | column -t -s '|'
Here is how my alias section looks like
This is the output of the commands
➜ scala git:(2.12.x) git unmerged
fatal: Unknown commit master
There are no local branches out of sync with master
➜ scala git:(2.12.x) git merged
(origin/2.11.x) 1fcfdd8 Lukas Rytz 4 days ago
(HEAD, origin/HEAD, origin/2.12.x, 2.12.x) 0e4c39a Vlad Ureche 2 days ago
Author Miro Adamy
LastMod 2016-03-23
License (c) 2006-2020 Miro Adamy