Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I often have at least 3 remote branches: master, staging, and production. I have 3 local branches that track those remote branches.

Updating all my local branches is tedious:

git fetch --all

git rebase origin/master

git checkout staging

git rebase origin/staging

git checkout production

git rebase origin/production

I'd love to be able to just do a "git pull -all", but I haven't been able to get it to work. It seems to do a "fetch --all", then updates (fast forward or merges) the current working branch, but not the other local branches.

I'm still stuck manually switching to each local branch and updating.

1 Answer

0 votes
by (27.5k points)

The behavior you describe for pull --all is exactly as expected, though not necessarily useful. That option is passed along to git fetch, which then fetches all refs from all remotes, instead of just the needed one; pull then merges (or in your case, rebases) the appropriate single branch.

If you want to check out other branches, you're going to have to check them out. And yes, merging (and rebasing) absolutely require a work tree, so they cannot be done without checking out the other branches. You could wrap up your described steps into a script/alias if you like, though I'd suggest joining the commands with && so that should one of them fail, it won't try to plow on.

Browse Categories

...