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.
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.
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.
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.
You should be able to use the git show-ref
command. git-show-ref docs
git show-ref --heads -s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With