Notes by Lesnitsky Subscribe

#bash ยท 2020-03-25 07:04 PM Twitter Logo

Bash: how to assign current git branch name to a variable

You can use the following git command:

#!/bin/bash git symbolic-ref HEAD
# example: refs/heads/master

To get a short branch name

#!/bin/bash

current_branch=$(git symbolic-ref --short HEAD)