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

Answer by Max for How to get the current branch name in Git?

As of version 2.22 of git you could just use: git branch --show-current

View Article


Answer by Joseph Lust for How to get the current branch name in Git?

You can do this with a single grep instruction, using Perl mode and \K to reset the match buffer, so you get only the branch name. $ git branch | grep -oP "^\*\s+\K\S+$" master

View Article


Answer by v.babak for How to get the current branch name in Git?

Get local branch name only: git status -b -u no | awk 'NR==1{print $3;}' Get remote branch name only: git status -b -u no | awk 'NR==2{print $6;}' and git status -b -u no | awk 'NR==2{print $6;}' | tr...

View Article

Answer by glisu for How to get the current branch name in Git?

Use git branch --contains HEAD | tail -1 | xargs it also works for "detached HEAD" state.

View Article

Answer by okTalk for How to get the current branch name in Git?

I know this has been answered already, but in the most recent version of Git the command git branch opens a list of your branches in some kind of prompt that you have to quit out of. Which annoys me to...

View Article


Answer by Lawrence Paje for How to get the current branch name in Git?

git branch show current branch name only. While git branch will show you all branches and highlight the current one with an asterisk, it can be too cumbersome when working with lots of branches. To...

View Article

Answer by dgolovin for How to get the current branch name in Git?

A less noisy version for git status would do the trick git status -bsuno It prints out ## branch-name

View Article

Answer by jackotonye for How to get the current branch name in Git?

I recommend using any of these two commands. git branch | grep -e "^*" | cut -d' ' -f 2 OR git status | sed -n 1p | cut -d' ' -f 3 OR (more verbose) git status -uno -bs| cut -d'#' -f 3 | cut -d . -f 1|...

View Article


Answer by Satheesh Kumar for How to get the current branch name in Git?

git status will also give the branch name along with changes. e.g. >git status On branch master // <-- branch name here .....

View Article


Answer by Shayan Amani for How to 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 to 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 HEAD This is a short version of @dmaestro12's answer and without tag support.

View Article

Answer by Prateek Gangwal for How to get the current branch name in Git?

you can use git bash on the working directory command is as follow git status -b it will tell you on which branch you are on there are many commands which are useful some of them are -s --short Give...

View Article

Answer by mrrusof for How to 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 to 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 to 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 git-aware-prompt...

View Article


Answer by cagney for How to 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 to get the current branch name in Git?

git branch | grep -e "^*" | cut -d' ' -f 2 will show only the branch name

View Article


Answer by Diego Pino for How to 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/bash git branch | grep -e "^*" I put this script in a custom folder (~/.bin). The folder is in...

View Article

Answer by dmaestro12 for How to 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 function:...

View Article

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

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

View Article
Browsing all 96 articles
Browse latest View live


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