17

Most magit commands are invoked with a single key, which pops up a menu of subcommands and switches. For example, P shows P and t as subcommands and -f and -u as "switches."

Hitting the letters for the subcommands invokes them, but how does one invoke the switches? I have a repository with two remotes, and I wanted to push to the other remote. The -u switch looks like just the thing, but if I type P -u, the -u turns red, but Magit does not prompt for the remote.

The manual says nothing about these switches for any of the commands as far as I can tell.

Could someone explain how these switches are used in general. I'm not just concerned with this particular switch, but with the facility in general.

  • 4
    To push to a remote, add a prefix argument before hitting P P. – Tu Do Jan 14 '15 at 9:25
  • while pressing ? key from inside Magit is helpful to show the menu, some keys are still not there. E.g. Try l h for reflog. So, I agree with you that a more extensive menu/help is still in need. – doctorate Jan 14 '15 at 9:53
13

The way you are enabling the switches is correct, as evidenced by the fact that they "turn red" when you hit - followed by a letter.

In your case, -u simply isn't the switch you want. From man git-push:

-u, --set-upstream

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch.<name>.merge in git-config(1).

So when you push with the -u switch enabled, you'll see something like this in the *magit-process* buffer:

0 git --no-pager -c core.preloadindex=true push -v origin foo:refs/heads/foo -u

Pushing to https://example.com/project.git

Counting objects: 15, done. [...].

Branch foo set up to track remote branch foo from origin. [...]

This tells you that Magit did in fact consider the -u switch.


As @TuDo points out, to get Magit to prompt you for a remote to push to, you need to hit C-u P P.


Switches and Args

In general, when dealing with the menus that Magit provides for different commands it is helpful to remember that switches are just that: switches. You can turn them on and off, and that's it. They don't require you to supply any additional information, so Magit won't prompt you for anything when you turn them on.

Args, on the other hand, do require additional information, so when you tell Magit that you want to run a command with a specific arg it will prompt you accordingly. Args also differ from switches in that they are enabled by hitting = followed by a letter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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