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

Answer by skippy for How to 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 1p Explanation: git status -> gets the working tree status sed -n 1p -> gets the first...

View Article


Answer by Ryan for How to 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 | rev Update This is nicer if you have and aren't...

View Article


Answer by karthikr for How to 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 status works, but...

View Article

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

you can also use GIT_BRANCH variable as appears here: https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin The git plugin sets several environment variables you can use in your scripts: GIT_COMMIT -...

View Article

Answer by Silas Barta for How to 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...

View Article


Answer by Stefaan for How to 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 at):...

View Article

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

git symbolic-ref -q --short HEAD I 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 to get the current branch name in Git?

git branch | grep "*" | sed "s/* //" | awk '{printf $0}' | pbcopy To directly copy the result to the pasteboard. Thanks to @olivier-refalo for the start…

View Article


Answer by ShogunPanda for How to 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


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

To display the current branch you're on, without the other branches listed, you can do the following: git rev-parse --abbrev-ref HEAD Reference: Show just the current branch in Git (Sep 2009)

View Article

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

In Netbeans, ensure that versioning annotations are enabled (View -> Show Versioning Labels). You can then see the branch name next to project name. http://netbeans.org/bugzilla/show_bug.cgi?id=213582

View Article

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

You have also git symbolic-ref HEAD which displays the full refspec. To show only the branch name in Git v1.8 and later (thank's to Greg for pointing that out): $ git symbolic-ref --short HEAD On Git...

View Article

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

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...

View Article


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

#!/bin/bash function git.branch { br=`git branch | grep "*"` echo ${br/* /} } git.branch

View Article

Answer by Jakub Narębski for How to get the current branch name in Git?

Why not use git-aware shell prompt, which would tell you name of current branch? git status also helps. How git-prompt.sh from contrib/ does it (git version 2.3.0), as defined in __git_ps1 helper...

View Article


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

You can just type in command line (console) on Linux, in the repository directory: $ git status and you will see some text, among which something similar to: ... On branch master ... which means you...

View Article

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

git branch should show all the local branches of your repo. The starred branch is your current branch. If you want to retrieve only the name of the branch you are on, you can do: git branch | grep \* |...

View Article


How to get the current branch name in Git?

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 sure when I am editing a file in NetBeans...

View Article

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

You can also see name of current branch in your .git directory of current project.type command in terminal: open .git/HEAD output file contains the name of current branch ref:...

View Article

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

In case your CI server does not have environment variable with branch name and you have a dockerized build without git binary inside of container, you can just use:cat .git/HEAD | awk -F '/''{print $NF}'

View Article
Browsing all 96 articles
Browse latest View live


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