Listing all branches and querying whether the local repo is in sync with remote

Advertisements

Given

F---E---D----B---A
            /        
           C [branch name]

git branch --all lists all branches both locally and remotely. The output is something like:

C
*master
/remotes/origin/C
/remotes/origin/master

I would like to get information on whether all local and remote branches are up to date and fully synched with no local commit that has not yet been pushed to the remote. That is, if on branch C, I have a commit locally that has not yet been pushed, how can such information be obtained?

I can switch to branch C locally via a checkout and issue a git status but is there a way to do it for all branches automatically via a single command?

>Solution :

git branch -vv should show you what you are looking for.

This will show your local branches along with the remote that they are tracking to plus whether they are ahead, behind or both of the remote.

Remotes are always going to be in sync because track to what your repo sees what is on origin and the only way to find out if they are behind is by doing a git fetch which then updates the remote branches bringing them up-to-date. (it gets kind of circular)

If you only want to see the branches that are out of sync you can use this: git branch -vv | grep -E "ahead [0-9]|behind [0-9]"

Leave a ReplyCancel reply