Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a character for "current branch" in git?

Tags:

git

I need to retype my current branch name constantly.

Examples

Updating my current branch with the changes from remote

git pull origin mySuperLongComplicatedBranchName

Push my current branch to remote

git push origin mySuperLongComplicatedBranchName

I would to simplify this to a simple:

git pull origin *

or something similar. Unless maybe something like this already exists. I'm fairly used to git, but am just hoping I'm missing something simple.

EDIT:

Adding extra info in response to the one comment:

git show-ref --head

eaadd6401c4e179c105ac3565fe9bf53e2882f83 HEAD 
eaadd6401c4e179c105ac3565fe9bf53e2882f83 refs/heads/myReallyLongBranchName
d6af452b1ad0a309a55061f9eeb6ab7ae83b6aef refs/remotes/origin/HEAD
eaadd6401c4e179c105ac3565fe9bf53e2882f83 refs/remotes/origin/myReallyLongBranchName`

so it looks like my remote reallyLongBranch looks identical to current head. Oh I know. I'll

git fetch

then I ran

git show-ref --head again

bc1b96345913e911d03eb62763f8795cc20ecd8f refs/remotes/origin/myReallyLongBranchName

Oh great. Now I must be able to do git pull origin HEAD.

I run the command. and I get an Already up to date.

Then I run:

git pull origin mySuperLongComplicatedBranchName

I get changes pulled down. Face palm.

It seems as though it doesn't work. Git knows what my current working branch name is... I wish there was just a symbol for it.

like image 827
EGHDK Avatar asked Jul 13 '17 20:07

EGHDK


2 Answers

You can use HEAD as "shortcut" for the current commit tree HEAD:

git push origin HEAD

git pull origin HEAD

HEAD usually points to the head commit of currently checked out branch.

EDIT: jtill reminded that we have @ as shortcut for HEAD, so it can be even simpler:

git push origin @

git pull origin @
like image 133
Alberto Trindade Tavares Avatar answered Oct 13 '22 10:10

Alberto Trindade Tavares


These are the shortcuts I use to push and pull, including getting the branch name (not just using HEAD, which points to a commit and will cause issues when pulling):

alias push='git push origin "$(git symbolic-ref --short HEAD)"'
alias pull='git pull origin "$(git symbolic-ref --short HEAD)"'
like image 22
DerTarchin Avatar answered Oct 13 '22 10:10

DerTarchin