Show git in front and behind information for all branches, including remotes

In a github project, you can go to the page / branches and get pretty graphs like these, which for each branch show how far behind and how far ahead each branch is relative to the master.

git branch ahead behind

Is there a command line tool that does something like this? Something that works with remotes? For example,

git branch -v -v 

close to what I'm looking for but works only for local branches.

+37
git
Oct 14 2018-11-21T00:
source share
3 answers

I was also interested, so I just hacked a git branch-status script that gives this information using git for-each-ref

 #!/bin/bash # by http://github.com/jehiah # this prints out some branch status (similar to the '... ahead' info you get from git status) # example: # $ git branch-status # dns_check (ahead 1) | (behind 112) origin/master # master (ahead 2) | (behind 0) origin/master git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \ while read local remote do [ -z "$remote" ] && continue git rev-list --left-right ${local}...${remote} -- 2>/dev/null >/tmp/git_upstream_status_delta || continue LEFT_AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta) RIGHT_AHEAD=$(grep -c '^>' /tmp/git_upstream_status_delta) echo "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) $remote" done 

Using:

 $ git branch-status dns_check (ahead 1) | (behind 112) origin/master master (ahead 2) | (behind 0) origin/master 
+46
Oct 14 2018-11-22T00:
source share

2015 update

My initial answer below is not ideal, as the upstream branch is not necessarily the branch you are clicking on. This is only the industry you are pulling from.

With Git 2.5+, the correct command is:

 git for-each-ref --format="%(refname:short) %(upstream:track)" refs/heads 

See more at View Unpushed Git Commits . "

(as indicated by void.pointer in the comments , upstream:track more accurate than push:track , depending on the default push policy)




Git 2.13 (Q2 2017) uses a more general ref filter API filter with a more comprehensive git for-each-ref push :

See commit 3d9e4ce , commit 949af06 , commit 56b4360 , commit 6eac70f , commit 1a34728 , commit 1a0ca5e , commit 3a42980 , commit 17938f1 , commit 3ba308c , commit a798410 , commit b180e6f , commit 01f9582 , commit bbc4949 , fbf4949 commit 42d0eb0 , commit 4f3e3b3 , commit c58f c85 (January 10, 2017) Karthik Nayak ( KarthikNayak ) .
(merged Junio ​​C Hamano - gitster - into commit 93e8cd8 , February 27, 2017)

 push: 

The name of the local ref that represents the location @{push} for the displayed link.
Corresponds to :short :lstrip :rstrip :track and :trackshort parameters like upstream .
Produces an empty string if @{push} ref is not configured.

If lstrip=<N> ( rstrip=<N> ) is added, separate the <N> path components separated by a slash from the front (back) (for example, %(refname:lstrip=2) turns refs/tags/foo into foo and %(refname:rstrip=2) turns refs/tags/foo into refs ).

If <N> is a negative number, separate as many path components from the specified end as possible to leave the path components -<N> (for example, %(refname:lstrip=-2) turns refs/tags/foo into tags/foo and %(refname:rstrip=-1) turns refs/tags/foo into refs )




Original answer (2014)

Another way will be available with Git 1.9 / 2/0 (Q1 2014).
See commit b28061c from Ramkumar Ramachandra (artagnon) :

for-each-ref : enter %(upstream:track[short])

Introduction:

  • %(upstream:track) to display " [ahead M, behind N] " and
  • %(upstream:trackshort) to display " = ", " > ", " < " or " <> " respectively (based on contrib/completion/git-prompt.sh ).

Now you can use the following for-each-ref format:

 %(refname:short) %(upstream:trackshort) 

to display links with brief tracking information.

Note that :track and :trackshort only work with " upstream " and fail when using anything else.

+19
Dec 10 '13 at 16:21
source share

For this type of problem you can use "gitk" `

 sudo apt-get update sudo apt-get install gitk 

It can help you. You can even see git ahead for all branches

-6
Feb 16 '17 at 10:54 on
source share



All Articles