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

Answer by Diego Pino for How do I get the current branch name in Git?

$
0
0

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

So now when I'm in a git repo, I just simply type git cbr to print out the current branch name.

$ git cbr* master

This works because the git command takes its first argument and tries to run a script that goes by the name of git-arg1. For instance, git branch tries to run a script called git-branch, etc.


Viewing all articles
Browse latest Browse all 96

Trending Articles