Answer by Shayan Amani for How do I get the current branch name in Git?
Simply, add following lines to your ~/.bash_profile:branch_show() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'}export PS1="\u@\h...
View ArticleAnswer by user for How do I get the current branch name in Git?
Returns either branch name or SHA1 when on detached head:git rev-parse --abbrev-ref HEAD | grep -v ^HEAD$ || git rev-parse HEADThis is a short version of @dmaestro12's answer and without tag support.
View ArticleAnswer by Prateek Gangwal for How do I get the current branch name in Git?
you can use git bash on the working directorycommand is as followgit status -bit will tell you on which branch you are on there are many commands which are useful some of them are -s--shortGive the...
View ArticleAnswer by mrrusof for How do I get the current branch name in Git?
The following shell command tells you the branch that you are currently in.git branch | grep ^\*When you don't want to type that long command every time you want to know the branch and you are using...
View ArticleAnswer by Abdennour TOUMI for How do I get the current branch name in Git?
Add it to PS1 using Mac : PS1='\W@\u >`[ -d .git ] && git branch | grep ^*|cut -d"" -f2`> $ 'Before running the command above : After running that command : Dont worry, if it is not GIT...
View ArticleAnswer by Kirill Zhuravlov for How do I get the current branch name in Git?
You can permanently set up your bash output to show your git-branch name. It is very handy when you work with different branches, no need to type $ git status all the time. Github repo...
View ArticleAnswer by cagney for How do I get the current branch name in Git?
Using earlier ideas; assuming sha1 is 40 characters; and chasing references (yea, should delete the debug print lines :-):git reflog | awk '$3 == "checkout:"&& (sha == "" || sha == $1 ) {...
View ArticleAnswer by ungalcrys for How do I get the current branch name in Git?
git branch | grep -e "^*" | cut -d'' -f 2will show only the branch name
View ArticleAnswer by Diego Pino for How do I get the current branch name in Git?
I have a simple script called git-cbr (current branch) which prints out the current branch name.#!/bin/bashgit branch | grep -e "^*"I put this script in a custom folder (~/.bin). The folder is in...
View ArticleAnswer by dmaestro12 for How do I get the current branch name in Git?
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...
View ArticleAnswer by Filip Spiridonov for How do I get the current branch name in Git?
One more alternative:git name-rev --name-only HEAD
View ArticleAnswer by skippy for How do I get the current branch name in Git?
I know this is late but on a linux/mac ,from the terminal you can use the following.git status | sed -n 1pExplanation:git status -> gets the working tree statussed -n 1p -> gets the first line...
View ArticleAnswer by Ryan for How do I get the current branch name in Git?
If you really want the last branch/tag checked out in detached HEAD state as well.git reflog HEAD | grep 'checkout:' | head -1 | rev | cut -d'' -f1 | revUpdateThis is nicer if you have and aren't...
View ArticleAnswer by karthikr for How do I get the current branch name in Git?
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 statusworks, but only...
View ArticleAnswer by user3405314 for How do I get the current branch name in Git?
if you run in Jenkins, you can use GIT_BRANCH variable as appears here:https://wiki.jenkins-ci.org/display/JENKINS/Git+PluginThe git plugin sets several environment variables you can use in your...
View ArticleAnswer by Silas Barta for How do I get the current branch name in Git?
Found a command line solution of the same length as Oliver Refalo's, using good ol' awk:git branch | awk '/^\*/{print $2}'awk reads that as "do the stuff in {} on lines matching the regex". By default...
View ArticleAnswer by Stefaan for How do I get the current branch name in Git?
For my own reference (but it might be useful to others) I made an overview of most (basic command line) techniques mentioned in this thread, each applied to several use cases: HEAD is (pointing...
View ArticleAnswer by Kousha for How do I get the current branch name in Git?
git symbolic-ref -q --short HEADI use this in scripts that need the current branch name. It will show you the current short symbolic reference to HEAD, which will be your current branch name.
View ArticleAnswer by SushiGrass Jacob for How do I get the current branch name in Git?
git branch | grep "*" | sed "s/* //" | awk '{printf $0}' | pbcopyTo directly copy the result to the pasteboard. Thanks to @olivier-refalo for the start…
View ArticleAnswer by ShogunPanda for How do I get the current branch name in Git?
What about this?{ git symbolic-ref HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null } | sed "s#refs/heads/##"
View Article