Is there a shortcut to tell Git to push the current tracking branch to origin?
Note: I know that I can change the default push behavior, but I am looking for an ad-hoc solution that does not change the default behavior.
For example, suppose I am on branch feature/123-sandbox-tests
I would be using
git push origin feature/123-sandbox-tests
which is tedious. I am looking for a shortcut, something like
git push origin current # <- example, not working
where git knows that current is feature/123-sandbox-tests
.
Edit: Starting from version 2.0, git's default behavior has changed to a more intuitive behavior, which is what I wanted to achieve. See This SO question for details.
Edit 2: ceztko's answer is the best answer as it allows to push the current branch, regardless of the settings.
By default, Git chooses origin for the remote and your current branch as the branch to push. If your current branch is main , the command git push will supply the two default parameters—effectively running git push origin main .
The git push -u <remote> <branch name> command uploads content from a local repository to a remote repository. It is generally used to upload modifications in a local repository with remote team members.
According to git push
documentation:
git push origin HEAD A handy way to push the current branch to the same name on the remote.
So I think what you need is git push origin HEAD
. Also it can be useful git push -u origin HEAD
to set upstream tracking information in the local branch, if you haven't already pushed to the origin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With