Skip to content

Instantly share code, notes, and snippets.

Created September 15, 2017 02:15
What would you like to do?
Git pull all remote branches
#!/usr/bin/env bash
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
Copy link

Wandalen commented Jun 1, 2022

According to the doc on pull, the --all option only affects the fetch part of the pull command.
So isn't it kind of useless to do a fetch --all before a pull --all ?
Also I have doubts that git pull --all does indeed pull all remote branch and not just the current one.
What do you think ?

Confirmed. That is useless. Any working alternative?

Copy link

jcwren commented Jun 29, 2022

git branch -r | grep -v '->' | tr -d 'origin/' | while read remote; do echo "parsing branch $remote"; git checkout "$remote"; git reset --hard $remote ; git pull; echo "$remote done";done

Your tr command is incorrect, as it deletes characters in the list. You want sed.

$ echo "origin/docubranch" | tr -d 'origin/'
$ echo "origin/docubranch" | sed -e 's/^origin\///'

Copy link

m3asmi commented Jul 13, 2022

@jcwren thanks, I fixed it

Copy link

This was so helpful! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment