Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 'git pull' all the branches easily?

git pull --help

Incorporates changes from a remote repository into the current branch.

I pull the git repository for offline view of the code and like to have the updated code for the different branches. How do I pull the code for all the branches easily without doing a pull for each branch manually?

--all -- Fetch all remotes.

--all didn't help.

like image 603
Praveen Sripati Avatar asked Sep 27 '11 07:09

Praveen Sripati


2 Answers

If the local repository is used for read only and none of the files are modified, then the below script will do the trick.

for i in $(git branch | sed 's/^.//'); do git checkout $i; git pull; done

There seems to be no git equivalent command for the same.

like image 146
Praveen Sripati Avatar answered Sep 25 '22 10:09

Praveen Sripati


Like Praveen Sripati's answer, but as a shell function and it brings you back to the branch you started on.

Just put this in your ~/.bash_aliases file:

function pull-all () {
    START=$(git branch | grep '\*' | set 's/^.//');
    for i in $(git branch | sed 's/^.//'); do
        git checkout $i;
        git pull || break;
    done;
    git checkout $START;
};

With the || break it does a satisfactory job not screwing things up if there's a conflict or the like.

like image 24
cellofellow Avatar answered Sep 26 '22 10:09

cellofellow