Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of branch heads in Git?

Tags:

I am trying to get a list of branch heads in Git. So far I have found git log --simplify-by-decoration which seems to include all branches and show the heads, but it also shows one extra commit which is useless for me. Is there an even better way to do this or is that what I should use?

So to make it clear: I want to have an output that gives me the head of all branches in my local repository. Basically, I just need the hash of each of the heads, but I can just regex it from whatever output I get.

like image 931
Tower Avatar asked Nov 20 '11 13:11

Tower


People also ask

How do you find the head of the branch?

In Git, a head is a ref that points to the tip (latest commit) of a branch. You can view your repository's heads in the path . git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch.

How do I find my git head?

The git show head is used to check the status of the Head. This command will show the location of the Head. Syntax: $ git show HEAD.

What is the git command to see 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.


1 Answers

You should be able to use the git show-ref command. git-show-ref docs

git show-ref --heads -s 
like image 73
loganfsmyth Avatar answered Oct 06 '22 13:10

loganfsmyth