Reputation: 1473
When pushing and creating a remote branch name using git push -u <remote-name> <remote-branch-name>
, I always have to enter in a remote branch name. Example:
git push -u origin my-local-branch-123
However, if my remote branch name will be the same as my local branch name why do I have to write it? Is it possible to automatically use the local branch name as the remote branch name? If not, is there a shortcut?
If I try to simply do, without a remote branch name:
git push -u origin
I receive an error stating:
fatal: The current branch my-local-branch-123 has no upstream branch.
Tl;dr: I do not want to enter the name of the new remote branch myself. I want git to automatically use my local branch name as the remote name when doing git push -u
. A shortcut will be great as well!
Thank you!
Edit: This is not a duplicate of this questions as I'm not asking about the default behaviour of push, I know the default behaviour (it will push to the associated branch if one is set). I'm trying to find how to set the local branch name as the remote branch name.
Upvotes: 2
Views: 517
Reputation: 2736
git push origin HEAD
(I do believe, it hasn't failed me yet)
HEAD
is equivalent to the current branch you are on so it'll "expand" to git push origin my-local-branch-123
Then simply include your -u
flag to get git push -u origin HEAD
and you should be done.
Upvotes: 2