How do you refresh the remotes in Magit?
Asked Answered
F

1

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?

Footed answered 14/6, 2014 at 3:36 Comment(0)
G
14

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>.

Greenlee answered 14/6, 2014 at 4:30 Comment(9)
you also have "f a" to fetch all remoteGluconeogenesis
@Rémi true, I have included your comment in the answer for more visibility.Greenlee
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.Footed
F F isn't available any more in the current versions.Woven
@Woven what shortcut would be used for git fetch then (in the current versions)?Greenlee
@Greenlee F F used to do a git pull. A git fetch is still done using the f submenu.Woven
@Woven OK: what shortcut would be used for git pull now?Greenlee
@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).Woven
@Woven Thank you. I have included your comment in the answer for more visibility.Greenlee

© 2022 - 2024 — McMap. All rights reserved.