0

No matter how I fiddle with magit options, I cannot reproduce the following behavior:

  • I checkout origin/master.
  • I create a new feature-branch on top of it; its name is unique.
  • I make changes, add commits to that branch.
  • I push the branch, and it ends up as origin/feature-branch.

This behavior is trivially achieved by git push -u.

From within magit, the "Push" popup suggests to set upstream, but it suggests master, or other existing upstream branches.

I want my local name branch be settable as upstream, or the push remote branch, without copy-pasting.

An elisp snippet to set the upstream branch would be equally helpful.

1 Answer 1

2

Instead of pushing to the upstream using P u, use P p to push to the "push target".

Its useful to treat origin/master (or master) as "the" other branch related to feature-branch. Its equally useful to treat origin/feature-branch (or fork/feature-branch) as the other branch.

Luckily you don't have to choose, because Git supports associating two distinct other branches with the current branch. The "upstream" and the "push-target branch" (the branch by the same name as the local branch on the push-remote).

This is explained in more detail in The Two Remotes.

3
  • It's good to know! But I still cannot have my current local branch name automatically inserted into the Pp list or into the bC list, or any auto-completions therein. I have to manually copy-paste it. What I want to avoid is the copy-pasting.
    – 9000
    Commented May 3, 2019 at 18:22
  • These commands prompt for a remote, not a branch. The push-remote is a remote. It can be configured per-branch using branch.<branch>.pushRemote or for all branches using remote.pushDefault. Git enforces that the "push remote branch" always has the same name as the local branch, you cannot use another name. If you have a single remote, then you can just accept the default using RET, otherwise you have to select a remove.
    – tarsius
    Commented May 3, 2019 at 19:04
  • Indeed, doing Pp and replying "origin" (or whatever other remote name) works as desired! It does not set the branch for Pu, though, so following pushes need to be Pps, too.
    – 9000
    Commented Jul 17, 2019 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.