Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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]"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading