3

git branch -v shows a very nice list of all branches with their refs and last commit title. I would like to include that information (i.e. branch name, ref and commit title) in the log output from a script, but I only want it for the currently active branch.

Is there a way to get git to show me just the current branch?

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
  • If you really want the format of `git branch -v`, why not just grep for the branch name you desire? Do note that that output is for human consumption, not machine, and is subject to change. If you want something in particular, be more specific in your question. There are certainly better ways to go about this. – Jonathon Reinhart Aug 02 '16 at 00:47
  • I want the branch name, ref number, and last commit title – John F. Miller Aug 02 '16 at 00:51
  • 1
    With Git 2.22 (Q2 2019), you will have a simpler approach based on `git branch --show-current`. See [my answer here](https://stackoverflow.com/a/55088865/6309). – VonC Mar 10 '19 at 14:51

2 Answers2

3

Something like this should work

git branch --list -v `git rev-parse --abbrev-ref HEAD`
Phil
  • 157,677
  • 23
  • 242
  • 245
0

You can try:

git branch -v | grep -e "^*"

The grep -e "^*" term should filter out all branches except the current one, whose listing should start with an asterisk.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360