-
-
Save grimzy/a1d3aae40412634df29cf86bb74a6f72 to your computer and use it in GitHub Desktop.
#!/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 |
for abranch in $(git branch -a | grep -v HEAD | grep remotes | sed "s/remotes\/origin\///g"); do git checkout $abranch ; done
This statement will checkout all branches when executed in local repo location. I use it frequently.
Thank you for this! It was very helpful.
thank you
I use this:
git branch -r | grep -v '\->' | sed -e 's/^origin\///' | while read remote; do echo "parsing branch $remote"; branch=${remote/origin\//}; git checkout "$branch"; git reset --hard $remote ; git pull; echo "$remote done";done
I think git is still being developed. Its like another programming language on its own. I'd like all GUI usage with drag and drop in the future
Hi,
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?
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/'
emtesdcubach
$ echo "origin/docubranch" | sed -e 's/^origin\///'
docubranch
@jcwren thanks, I fixed it
This was so helpful! Thank you!
great
Going to come in with a controversial new option:
git branch --remote | cut -c 10- | xargs -d\\n -n1 git switch -f
Just make sure you've committed or stashed all of your changes. This does assume that your remote is called origin
, if it's not, change the number of digits getting slashed by cut.
Mine own approach to pull and sync:
- https://github.com/andry81/gitcmd (implementation, not interactive usage)
git_pull_remote*.sh
git_sync_remotes.sh
- https://github.com/andry81/gituserbin (wrappers, interactive usage)
pull-remote*.*
sync-remotes.*
current=$(git branch --show-current) ; for brname in $(git branch -r | grep origin | grep -v master | grep -v HEAD | awk '{gsub(/^[^\/]+//,"",$1); print $1}'); do echo git checkout $brname ; git checkout $brname ; echo git pull ; git pull ; done ; echo git checkout $current ;git checkout $current