Git fetch all remote branches

git branch -r | awk -F'/' '{print "git fetch "$1,$2}' | xargs -I {} sh -c {}

By: cakyus
2014-10-25 07:36:50

What Others Think

Hmm... You need to filter out the HEAD line (it's just a pointer, not a branch): "remotes/origin/HEAD -> origin/master" git branch -r | grep -v -- "->" | ... This will also fail if there are / characters in the branch names (for example people using gitflow: feature/widget). Awk now becomes a bit ugly: ... | awk '{ i=index($0,"/"); printf "git fetch %s %s\n",substr($0,0,i-1),substr($0,i+1); }' | ... I might also be tempted to change your use of xargs. Consider: echo origin master | xargs -n2 git fetch This changes the original command into: git branch -r | awk -F'/' '{print $1,$2}' | xargs -n2 git fetch or git branch -r | grep -v -- "->" | awk '{ i=index($0,"/"); printf substr($0,0,i-1),substr($0,i+1); }' | xargs -n2 git fetch
flatcap · 361 weeks and 1 day ago
Hi, i'm surprise how quickly i got response here. Yes, flatcap .. my command will fail if there are / characters in the branch names. Your's looks good to me.
cakyus · 361 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: