I have a problem when working on too many branches, it takes a lot of time to find which is the current branch I am working on right now. Is there a way to list the current branch on top of the list that shows up when using the git branch command?
I have a problem when working on too many branches, it takes a lot of time to find which is the current branch I am working on right now. Is there a way to list the current branch on top of the list that shows up when using the git branch command?
If the git branch --show-current command is not available with your Git version, you could use one of these commands instead:
$ git checkout master
$ git rev-parse --symbolic-full-name HEAD
refs/heads/master
$ git rev-parse --abbrev-ref HEAD
master
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref --short HEAD
master
cf. the official doc:
git rev-parse --symbolic-full-name
This is similar to --symbolic, but it omits input that are not refs (i.e. branch or tag names; or more explicitly disambiguating "heads/master" form, when you want to name the "master" branch when there is an unfortunately named tag "master"), and show them as full refnames (e.g. "refs/heads/master").
git rev-parse --abbrev-ref[=(strict|loose)]
A non-ambiguous short name of the objects name. […]
git symbolic-ref <name>
Given one argument, reads which branch head the given symbolic ref refers to and outputs its path, relative to the
.git/directory. Typically you would giveHEADas the<name>argument to see which branch your working tree is on.
git symbolic-ref --short <name>
When showing the value of as a symbolic ref, try to shorten the value, e.g. from
refs/heads/mastertomaster.
and note that the git rev-parse solution is "compatible" with detached HEAD mode, that is, if no branch is currently checked-out, and HEAD merely points to a SHA1 reference, the two git rev-parse commands considered above will just output "HEAD":
$ git checkout 56e23844e80e6d607ad5fa56dfeedcd70e97ee70
Note: checking out '56e23844e80e6d607ad5fa56dfeedcd70e97ee70'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
[…]
$ git rev-parse --symbolic-full-name HEAD
HEAD
$ git rev-parse --abbrev-ref HEAD
HEAD
$ git rev-parse HEAD
56e23844e80e6d607ad5fa56dfeedcd70e97ee70