Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Include current branch in git alias



I have a simple git alias:

shipit = push origin master

Is there any way to detect the current branch?

For example: push origin 'currentbranch'

like image 952
Koxzi Avatar asked Mar 16 '23 08:03


2 Answers

Use HEAD to reference the current branch.

shipit = push origin HEAD
like image 137
Derek Avatar answered Mar 26 '23 03:03


There might not be a current branch ("detached HEAD" mode, where HEAD contains a raw SHA-1 instead of a branch name).

If there is a current branch, it is stored as a symbolic reference in HEAD:

$ git symbolic-ref HEAD
$ git symbolic-ref --short HEAD

If HEAD is detached:

$ git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

For the particular case of pushing, as Derek S already answered, you can just use the name HEAD directly. (This works for some other commands too; for those where it's not available, use git symbolic-ref.)

like image 29
torek Avatar answered Mar 26 '23 02:03