11

Magit is really nice, but I have yet to figure out how to create a remote branch from it, or how to refresh the remote branches it knows without deleting the remote and adding it back in. Currently I go to github, add a branch, then go into magit, delete the remote, and then add it back. Is there a better way?

user967953
  • 163
  • 2
  • 7

1 Answers1

15

Refreshing a remote branch should be done with a git fetch.

With Magit (documentation):

Typing f f will run git fetch.
It will prompt for the name of the remote to update if there is no default one.

Typing f o will always prompt for the remote.

Typing F F will run git pull.
When you don’t have a default branch configured to be pulled into the current one, you will be asked for it.

As Rémi commented, f a would fetch all remotes.

Actually, as akaihola comments in 2018:

If you type F, you get the "pull" menu.
Then:

  • p pulls from the push default (see b M-p), and
  • e from elsewhere (e.g. another remote branch).

Creating a remote branch should be pushing a local branch to a remote:

Magit will run git push when you type P P.
If you give a prefix argument to P P, you will be prompted for the repository to push to.
When no default remote repository has been configured yet for the current branch, you will be prompted as well.

Typing P P will only push the current branch to the remote.
In other words, it will run git push <remote> <branch>.

The branch will be created in the remote if it doesn’t exist already.
The local branch will be configured so that it pulls from the new remote branch.

If you give a double prefix argument to P P, you will be prompted in addition for the target branch to push to.
In other words, it will run git push <remote> <branch>:<target>.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 2
    you also have "f a" to fetch all remote – Rémi Jun 14 '14 at 05:50
  • @Rémi true, I have included your comment in the answer for more visibility. – VonC Jun 14 '14 at 05:52
  • Awesome. Fetch `a` is partly what I was looking for, It causes new remotes to show up in the remote manager. I never noticed that a push caused the remote branch to be created if it didn't exist or that `-u` would get me a prompt. I suspect I'm missing something about the prefixes to push. I see `-force` `-upstream` and `-dry run`. So I think I might be confused about prefix arguments. – user967953 Jun 16 '14 at 02:12
  • `F` `F` isn't available any more in the current versions. – akaihola Jul 10 '18 at 07:07
  • @akaihola what shortcut would be used for `git fetch` then (in the current versions)? – VonC Jul 10 '18 at 07:09
  • @VonC `F` `F` used to do a `git pull`. A `git fetch` is still done using the `f` submenu. – akaihola Jul 27 '18 at 22:11
  • @akaihola OK: what shortcut would be used for `git pull` now? – VonC Jul 28 '18 at 04:16
  • @VonC, if you type `F`, you get the "pull" menu. Then `p` pulls from the push default (see `b` `M-p`), and `e` from elsewhere (e.g. another remote branch). – akaihola Oct 12 '18 at 18:49
  • @akaihola Thank you. I have included your comment in the answer for more visibility. – VonC Oct 12 '18 at 20:14