0

I work with multiple branches, but I'm only modifying one of them (I'll call it working). I'd like to be able to get the latest for working but also get the latest for all of my tracking branches. Since the other tracking branches are rarely modified, they can usually fast forward.

I'd hoped git-pull could do it, but this doesn't achieve my desired result:

git checkout working
git pull --ff-only --all

My local main branch wasn't modified: it is still behind the remote branch mine/main.

I can force the update to main:

git br -f main mine/main

But I'd rather something automatic and something safer so it only modifies the branch if it can be safely fast forwarded. However, I don't actually want to check out the branch since I'm not actively working on it and don't intend to merge.

There are a bunch of scripts on Can "git pull --all" update all my local branches?, but this question is about a solution built into git.

Related but unhelpful: Does a git pull update all tracked branches?

idbrii
  • 10,975
  • 5
  • 66
  • 107

1 Answers1

1

You can say

git fetch

to update all remote-tracking branches at once.

No local branches are updated when you do that, and there is no shortcut to do so; you have to do them one at a time. But you do not have to switch to each branch in order to update it; you can stay where you are, but say

git fetch origin mybranch:mybranch

to update a branch you are not on at the moment (but you will still have to do that for each branch individually). The local branch you specify with that command will be updated, but only if it can be fast-forwarded.

There are a bunch of scripts on Can git pull --all update all my local branches?, but this question is about a solution built into git.

You may not be getting the message from those answers. What they are telling you is that there is no such solution built into git; you have to write a script in order to do it.

Related but unhelpful

Again, you're perhaps not getting the message. It is helpful. You may not like what it is telling you, but the truth doesn't care what you like — and what it is telling you is the truth.

One more point: you may be maintaining too many local branches. I never make a local branch unless I am actively developing on it (or unless I need to merge another branch into it, but that rarely happens because merging is done through pull requests at the remote), and I delete the local branch as soon as it is merged. As a result, I never ever pull. I just git fetch from time to time and, if I need to see what has happened on a remote branch, I examine my corresponding remote-tracking branch directly, without making a local branch version of it.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • "You may not be getting the message from those answers." I've seen several git questions where new git features make the current answer obsolete. I'd hoped this was another such case. Regardless, if this is ever a supported feature, hopefully this question makes that answer easier to find. – idbrii Nov 25 '22 at 05:34
  • "I just git fetch from time to time." Do you have a local `main` branch? How does it get updated? – idbrii Nov 25 '22 at 05:37
  • "Do you have a local main branch?" No. To see how I work, see my essay here: https://stackoverflow.com/a/72201388/341994 – matt Nov 25 '22 at 10:06