There are several ways to set the upstream, while pushing or without pushing at the same time.
If magit-push-current-set-remote-if-missing
is non-nil
(the default), then you will see something like:
Push feature to
p pushRemote, after setting that
u @{upstream}, after setting that
e elsewhere
To push to origin/feature
and set that as upstream press u and then RET to accept the default completion candidate.
If magit-push-current-set-remote-if-missing
is nil
, then you would see this instead:
Push feature to
e elsewhere
If you did press p now, then you would be told that the upstream is not configured (implying that you cannot push to the upstream if there is no upstream).
But if magit-push-current-set-remote-if-missing
is nil
, then the list of switches would feature --set-upstream
, so you could use P - u p as you are used to (except that the second p is lowercase). There's one complication though: after changing the value of magit-push-current-set-remote-if-missing
you have to restart Emacs for --set-upstream
to appear or disappear.
Finally you can set the upstream using the "set upstream (and do nothing else)" command: b uorigin/master
RET. Note that when you use this approach, then you can only select a branch which already exists.
But it would be better to configure the push-remote and push to that. To learn more about the push-remote and how it differs from the upstream, see the Branching node in the info manual (the web version hasn't been updated yet).
Basically the upstream branch is the branch into which your feature branch will eventually be merged (by merging or rebasing, not by pushing), most likely origin/master
. And the push-remote is where you push your feature branches to while still working on them or so that someone else can merge them. If the local branch is named feature
and the push-remote is my-fork
, then pushing that branch using P p would push to my-fork/feature
. (The "push-to-branch" cannot be configured, the name of the branch on the push-remote is always the same as the local name.)
So while your question was something like "how do I push to the upstream, while configuring the upstream at the same time", my recommendation is to not push to the upstream at all, but to instead push to the push-remote.
Provided you have not changed the value of magit-push-current-set-remote-if-missing
you can configure the push-remote using P psome-remote
RET. But, since you likely push all feature branches to the same remote, it is better to set the push-remote once for all branches and be done with it: b and then M-p until the right remote is selected.
Also note that it should usually not be necessary to explicitly set the upstream branch. When you create a new branch and select a remote branch as starting-point, then that is used as the upstream.
Unfortunately the starting-point usually is a local branch and in that case Git by default doesn't use it as the upstream. But that can easily be fixed by running this once:
git config --global branch.autoSetupMerge always
The default value is true
, which means "set starting-point as upstream, provided it is a remote branch".
By the way, the same applies to the push-remote. That too should usually be set semi-automatically in "new" repositories. If you clone a repository, you will be asked whether you want to use origin
as the push-remote. You should answer "yes", unless you are going to add another remote, say my-fork
, which should be used as the push-remote. When you add a new remote using M a and remote.pushDefault
isn't set yet, then you will be asked whether you want to use the newly added remote as the push-remote.
This can be configured using magit-clone-set-remote.pushDefault
and magit-remote-add-set-remote.pushDefault
.
Another advanced option is magit-branch-prefer-remote-upstream
, which defaults to nil
. If you set it to t
, and then select a local branch as the starting-point for a new branch, then the upstream of the starting-point might (according to some rules, see doc-string) be used as the upstream, instead of the starting-point itself.
<remote>/<branch>
part was accidentally left out of the prompt (see this comment). In the meantime, you can setmagit-push-current-set-remote-if-missing
to nil.