Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Head commit for all remote branches using Git

I know how to list the remote branches

$ git branch -a

And I know how to find the head commit hash of my current branch

$ git rev-parse HEAD

But I'm not sure how to list all the head commit hashes for all the remote branches. This is close to what I want but what order are they in?

$ git rev-parse --remotes
4b9f7128e9e7fa7d72652ba49c90c37d0727123d
4ebab9616fac6896b7827e8502b4dc7c5aac6b5b
ea7a5fab4a757fb0826253acf1fe7d8c546c178e
...

Ideally, I'd like a list of branch-name commit-hash pairs or even a way to pass a remote branch name to git rev-parse HEAD

like image 485
milkplus Avatar asked Oct 08 '10 18:10

milkplus


People also ask

How do I commit all branches?

If you use git branches a lot, you'll often push each branch after each commit. Instead of pushing every single branch you can do git push --all origin . This will push all commits of all branches to origin.

How do I fetch all remote branches?

To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .

Does git pull pull all remote branches?

git fetch --all and git pull -all will only track the remote branches and track local branches that track remote branches respectively. Run this command only if there are remote branches on the server which are untracked by your local branches.


2 Answers

Use either

git branch -r -v --no-abbrev

and ignore part with commit message or

git show-ref

and filter results starting with refs/remotes.

like image 124
max Avatar answered Sep 18 '22 17:09

max


I know this is old and answered, but I think git ls-remote would work for this too.

git ls-remote --heads origin

fcce961b46784fae13be8a30c2622ddd34d970ec        refs/heads/develop
9da7bb692a72235451706f24790a3f7a100a64e2        refs/heads/feature-netty-testing
86020c50d86691caecff4a55d3b1f2f588f6291d        refs/heads/javafx-testing
871d715e5c072b1fbfacecc986f678214fa0b585        refs/heads/master
7ed641c96d910542edeced5fc470d63b8b4734f0        refs/heads/orphan-branch
like image 38
Ryan J Avatar answered Sep 17 '22 17:09

Ryan J