Eugen Konkov
Eugen Konkov

Reputation: 25133

How to push current branch to remote without setting upstream?

I can push branch to remote:

git push --set-upstream origin 293-error-pages

I can push branch without setting upstream by specifying current branch explicitly:

git push origin 293-error-pages

How to push current branch to remote? (and not specify its name explicitly)

git push origin

Tells me:

fatal: The current branch 293-error-pages has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin 293-error-pages

Upvotes: 6

Views: 2010

Answers (3)

Eugen Konkov
Eugen Konkov

Reputation: 25133

Another solution:

git push <remotename> <localcommit>:<remotebranch>

This will push <localcommit> to <remotebranch> or create it on server <remotename>

Upvotes: 0

Eugen Konkov
Eugen Konkov

Reputation: 25133

To push current branch to remote you should set/configure push.default to 'current'

git config --global push.default current

push.default
Defines the action git push should take if no refspec is explicitly given. current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

Upvotes: 7

Kousha
Kousha

Reputation: 1625

If you don't want to change your default for push.default, you can use the following command:

git push origin HEAD

https://git-scm.com/docs/git-push#Documentation/git-push.txt-codegitpushoriginHEADcode

Upvotes: 1

Related Questions