Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - push current branch shortcut

Tags:

git

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.

like image 693
Elad Avatar asked Dec 25 '12 15:12

Elad


People also ask

Does git push push current branch?

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 .

What is git push u?

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.


1 Answers

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.

like image 176
ceztko Avatar answered Oct 01 '22 11:10

ceztko