I often create new branches locally (e.g., newLocalBranch), and then push them to the upstream remote origin, thus creating a new remote branch, using git push -u origin newLocalBranch
. Is there a magit
function equivalent to this operation?
1 Answer
magit-push-current-to-pushremote
actually works perfect for me. If the branch already exists upstream, magit-push-current-to-pushremote
will just push the committed changes upstream. If the branch does not yet have an upstream location set, magit-push-current-to-pushremote
will prompt to select a remote location from the minibuffer (e.g., origin) to the branch to, defaulting to the same local name (i.e., newLocalBranch). Using magit-push
, instead, would fail because no upstream location has been set for the newLocalBranch yet.
Per the documentation for magit-push-current-to-pushremote
:
Push the current branch to ‘branch.<name>.pushRemote’. If that variable is unset, then push to ‘remote.pushDefault’.
When ‘magit-push-current-set-remote-if-missing’ is non-nil and the push-remote is not configured, then read the push-remote from the user, set it, and then push to it.
-
IIRC if you register the remote via
magit
it also offers to set the option and then the standard push does it too. Commented Mar 3, 2021 at 15:21 -
Please explain how that answers the question. Say what it does, for example.– DrewCommented Mar 3, 2021 at 15:49
-