re: My Personal Git Tricks Cheatsheet VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Track upstream branch alias git-up="git branch | sed -n -e 's/^\* \(.*\)/\1/p' | xargs git push -u origin " Assuming that you have set your git-b...
 

Git assumes the current branch implicitely, so the following also works:

alias git-up="git push -u origin"

Even better is to use a git alias for this:

git config --global alias.up 'push -u origin'

so you can use it like $ git up.

If you think you need to explicitly specify the branch anyway you can define an alias like this:

git config --global alias.up '!git push -u $(git-branch)'
 

Not specifying the branch still gives me a Fatal: The current branch has no upstream. Any ideas why?

Yep, I copied and pasted this exactly
git config --global alias.up 'push -u origin'

Ok, after some digging I got an alias to work. I have no idea why it works when nothing else I tried would but here it is anyway. I think it is best to paste the following into your .git-config file directly:

up = "!git push -u origin `git symbolic-ref --short HEAD`"

or if you have git 2.22

up = "!git push -u origin `git branch --show-current`"

I figured this out mostly by messing around with this Stack Overflow answer: stackoverflow.com/a/30529511/9770212

 

Nice! Thank you for the tips!

The git up alias is perfect.

code of conduct - report abuse