Alexander Zeitler

No more leaky abstractions

Git: fetch all branches from origin

Geschrieben von Alexander Zeitler am 10. August 2014

Tags: englishgit

When you’re using multiple remotes with Git, you may want to push everything from origin to the other remotes. Fetching all branches from origin manually can become a tedious task.

This post shows how to do it in a simple manner.

The solution is pretty symple - copy this bash script into a file named fetchall.sh and execute it inside your Git repository:

#!/bin/sh
remote=origin ;
for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; 
do git branch $brname  $remote/$brname ; done

Now all branches from origin get tracked and can be simply pushed all together using git push myotherremote --all.

blog comments powered by Disqus