3

While working on a project, it is necessary to pull some branches from remote and merge into current branch.

To update another branch, we have to

  • Stash local changes on current branch
  • Checkout to required branch (say foo)
  • Pull changes
  • Switch back to previous branch
  • Pop stash

All these steps can be done with single command on terminal using

git fetch origin foo:foo

How to do the same with magit in single step?

1
  • : fetch origin foo:foo (not intended to be facetious -- I'm just pointing out that you can run arbitrary git commands from inside git).
    – phils
    Commented Nov 30, 2016 at 4:40

1 Answer 1

3

In addition to @phils valid observation, there is f o for fetch other, you can then give it origin and then foo. This will update the origin/foo branch, rather than the foo branch.

Or you can use f r for fetch refspec and give it origin and foo:foo which will do exactly what your command line does.

4
  • Excellent. Is it possible to auto populate foo:foo, instead of typing them everytime? Commented Nov 30, 2016 at 6:02
  • 2
    Is there a reason why you want to fetch just that one branch instead of everything? The current interface was designed with the assumptions that just fetching everything isn't much of a deal because it is more convenient to tell git "get it all" as opposed to "get... wait... ah yes, /this/".
    – tarsius
    Commented Nov 30, 2016 at 10:55
  • @tarsius It would be great if all remotes can be fetched at once. However i wanted all PR's of a repo, i have updated ` fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` in git config. Now when i run f, r, origin, it just lists all available PR's and I have to type branch:branch everytime to fetch a branch. ` Commented Dec 3, 2016 at 15:33
  • @ChillarAnand f u will fetch all the configured branches, just like git fetch origin.
    – icarus
    Commented Dec 3, 2016 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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