2

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.

Abushawish
  • 1,466
  • 3
  • 20
  • 35
  • 1
    Possible duplicate of [Default behavior of "git push" without a branch specified](https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified) – jonrsharpe Jun 20 '18 at 16:11
  • I don't believe this is a duplicate. Please see my edit. Push needs to have a remote branch set, I'm asking on how to do that. The linked question is about the behaviour after a remote branch is set. Thanks! – Abushawish Jun 20 '18 at 17:49

1 Answers1

2

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.

Ripp_
  • 2,298
  • 1
  • 9
  • 12