I\'m from a Subversion background and, when I had a branch, I knew what I was working on with \"These working files point to this branch\".
But with Git I\'m not sur
Sorry this is another command-line answer, but that's what I was looking for when I found this question and many of these answers were helpful. My solution is the following bash shell function:
get_branch () {
git rev-parse --abbrev-ref HEAD | grep -v HEAD || \
git describe --exact-match HEAD 2> /dev/null || \
git rev-parse HEAD
}
This should always give me something both human-readable and directly usable as an argument to git checkout
.
feature/HS-0001
v3.29.5
git status
will also give the branch name along with changes.
e.g.
>git status
On branch master // <-- branch name here
.....
#!/bin/bash
function git.branch {
br=`git branch | grep "*"`
echo ${br/* /}
}
git.branch
Over time, we might have a really long list of branches.
While some of the other solutions are great, Here is what I do (simplified from Jacob's answer):
git branch | grep \*
Now,
git status
works, but only If there are any local changes
I know this is late but on a linux/mac ,from the terminal you can use the following.
git status | sed -n 1p
Explanation:
git status -> gets the working tree status
sed -n 1p -> gets the first line from the status body
Response to the above command will look as follows:
"On branch your_branch_name"
Well simple enough, I got it in a one liner (bash)
git branch | sed -n '/\* /s///p'
(credit: Limited Atonement)
And while I am there, the one liner to get the remote tracking branch (if any)
git rev-parse --symbolic-full-name --abbrev-ref @{u}