0

I really love the ability to use - as shorthand to refer to the last branch I was on.

I was wondering if there is shorthand to refer to the current branch I am on? For example,

Before

$(dev/my_branch)    git push -f origin dev/my_branch
$(dev/my_branch)    git branch --set-upstream-to=origin/dev/my_branch

After

$(dev/my_branch)    git push -f origin .
$(dev/my_branch)    git branch --set-upstream-to=origin/.
  • 1
    As both answers noted, `HEAD` means *the current branch*. However, it also means *the current commit*. It depends on how you ask the question. Use `git rev-parse --symbolic-full-name HEAD` or `git symbolic-ref HEAD` to ask the question *what is the **name*** and use `git rev-parse HEAD` to ask the question *what is the **hash ID***. – torek May 14 '20 at 22:49
  • The `git push` command is interesting in that it actually needs to ask *both* questions, internally, and will do so. – torek May 14 '20 at 22:50
  • 1
    Last, note that `@` by itself is a short way to spell `HEAD`. Given that you like `-` for "previous branch name" you might like this one-letter spelling. :-) None of this works for your `--set-upstream-to`, though, which demands that you spell out `origin/dev/my_branch`. I like to use `git push -u origin HEAD` to set it up initially, and then after that, just `git push -f` with no argument to update the current name after a rebase, provided I'm on a branch everyone agrees gets rebased like this. – torek May 14 '20 at 22:51

2 Answers2

1
git push origin HEAD

HEAD will always refer to the latest Commit of your current branch.

Alternative:

You can configure git to push to the current branch using the following command

git config --global push.default current

then just do

git push 

this will push the code to your current branch.

Rakmo
  • 1,588
  • 2
  • 17
  • 34
0

HEAD will refer to the current branch

user2199860
  • 740
  • 4
  • 13