5

Context: I have a relatively small project, in which I use branches to work on new features, so that when I'm finished, then I manually merge branches as I need.

I usually keep the same exact copy of my branches on many machines as I work remotely, and that's what I need. I'm not using GitHub, my remote server is just a Server of my company where we keep projects on.

So the question is: How do I push, or fetch all branches at once using magit?

What I'm trying to achieve is the same exact output that I would have by executing these commands in the terminal:

git push --all

or

git fetch --all

More info;

  • Emacs version: GNU Emacs 25.3.1 (x86_64-w64-mingw32) of 2017-09-17

  • Magit version: 20190202.1535

If more is needed don't mind asking. Thanks in advance!

4

Fetching

With the default Git configuration, fetching a remote will fetch all branches (i.e. all the refs the remote has under refs/heads/). So, from within Magit, you shouldn't need to do anything other than fetching the remote. If the remote is configured as the upstream, that would be F u with the default Magit bindings.

If you want to fetch all remotes (not just all branches from a single remote), you can do that with Magit's magit-fetch-all command (F a), as mentioned by @Prgrm.celeritas.

Pushing

Magit doesn't have a command that does something like git push --all REMOTE. As mentioned in another answer, you can run a custom Git command via the Magit interface.

Another option is to define a command yourself. For example,

(defun my/magit-push-all ()
  "Push all branches."
  (interactive)
  (magit-run-git-async "push" "-v"
                       (magit-read-remote "Remote")
                       "--all"))

And then bind that command in the push popup:

(magit-define-popup-action 'magit-push-popup
  ?a "Push all" #'my/magit-push-all)
  • Excuse me for the question; it is unclear to me to what you refer to as "Remote". Both in the code example and in the fetching part. In my case my only one remote is called origin. How can I set origin to be the remote for these commands that you pointed out? – Johwhite Feb 11 at 16:15
  • 1
    "Remote" was a general reference to any remote repository, but in the scenario you describe it'd be origin. For fetching, you can configure origin/master as the upstream branch for master (with the default Magit configuration, that'd be bu then select "origin/master"). Then you can fetch all branches on that remote with Fu ("fetch upstream"). For pushing with the custom command above, it will prompt you to choose a remote from all possible remotes. Because this is just "origin" in your case, you could replace (magit-read-remote "Remote") with "origin". – Kyle Meyer Feb 12 at 16:46
4

fa will fetch all remotes. I don't know if there is a way to push all remotes though. You could always use !! then push --all. !! lets you run any git command in the git root. Its what I use when magit doesn't have a popup option I need.

  • Thanks for your answer. fa is doing exactly what I needed for the download part. – Johwhite Feb 11 at 16:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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