When calling magit-push-current
with P P
from the status buffer, Magit 2.1.0
asks me where to push the branch on the first time, when upstream is not set.
How can it let automatically generate the name as it used to do before?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityUpdate: The "push branch" mentioned below has been implemented by now.See the documentation about branching for more information.
You have to set the upstream branch once. Once you have done that P P pushes to that and you will get lists of unpulled and unpushed changes in the status buffer (provided there are any).
There are various ways to set the upstream branch. You could use the --set-upstream
switch from the push popup: P -u P. Or use the command which sets the upstream and does nothing else: b u.
Also Magit now automatically sets the upstream branch when creating a new branch, provided the "starting point" is a branch name. This works for local and remote "upstreams". But note that if you pick a local branch as the starting point, then that won't help you with pushing. Pushing from the current repository to the current repository obviously doesn't make sense, and is disallowed.
So when the "upstream" branch is in fact another local branch, then P P behaves as if no upstream branch were configured, and behaves exactly like P e. The same is the case if no upstream is configured at all.
This due to a limitation in Git: one can only associate one other branch with some branch, and that branch is then called the "upstream branch". It would be better if there were at least an "upstream" and a "publish" branch. I intend to implement that in Magit eventually. See issue #1485.
So if you want to be able to push with just P P then the "upstream" branch has to be e.g. "origin/master", not "master".
I am considering adding a push variant which always runs just git push
without any arguments. What that does would then depend exclusively on Git configuration.
master
and it didn't set upstream, should I maybe branch from origin/master
to have the upstream automatically set?
Jul 7, 2015 at 16:23
origin/master
set origin/master
as upstream, but I would have expected to have origin/branch-name
as upstream.
Jul 7, 2015 at 16:54
P -p P <... completion ...> RET
Note that origin/branch-name
is offered as a completion candidate, so you don't have to type it out.
I use the following advice which automatically enables --set-upstream
when the current branch doesn't have an upstream yet:
(defun magit-push-arguments-maybe-upstream (magit-push-popup-fun &rest args)
"Enable --set-upstream switch if there isn't a current upstream."
(let ((magit-push-arguments
(if (magit-get-remote) magit-push-arguments
(cons "--set-upstream" magit-push-arguments))))
(apply magit-push-popup-fun args)))
(advice-add 'magit-push-popup :around #'magit-push-arguments-maybe-upstream)
Combined with ido completion this allows pushing a new branch with P P RET:
;; NOTE: requires ido-completing-read+
(setq magit-completing-read-function #'magit-ido-completing-read)
I just create the new branch with b c
and then edit the .git/config
file to point to origin/branch
rather than monkeying around with all the magit 2 stuff, which doesn't seem to work anyway.
Change:
[branch "fix_something"]
remote = .
merge = refs/heads/master
To
[branch "fix_something"]
remote = origin
merge = refs/heads/fix_something
This works, whereas I still haven't found a key combination in magit2 that accomplishes the same thing. Trying to set the remote doesn't work because it doesn't exist on origin yet.
bu
. But that uses git branch --set-upstream-to
and as you know Git cannot set a non-existent branch as the upstream and so Magit cannot either.
some-branch-name
to theorigin
remote, you can probably just typeo TAB s TAB
and you'll get the name you want.