Quantcast
Channel: How do I get the current branch name in Git? - Stack Overflow
Browsing all 96 articles
Browse latest View live

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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Image may be NSFW.
Clik here to view.

Answer 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 Article


Image may be NSFW.
Clik here to view.

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article


Answer 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 Article

Answer by Filip Spiridonov for How do I get the current branch name in Git?

One more alternative:git name-rev --name-only HEAD

View Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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
Browsing all 96 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>