8

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.

Community
  • 1
  • 1
Praveen Sripati
  • 32,799
  • 16
  • 80
  • 117
  • http://stackoverflow.com/questions/4318161/can-git-pull-all-update-all-my-local-branches should help – VonC Sep 27 '11 at 07:53
  • Possible duplicate of [Can "git pull --all" update all my local branches?](https://stackoverflow.com/questions/4318161/can-git-pull-all-update-all-my-local-branches) – krlmlr Apr 15 '19 at 19:36

6 Answers6

8

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.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
Praveen Sripati
  • 32,799
  • 16
  • 80
  • 117
7

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.

cellofellow
  • 437
  • 5
  • 14
5

pull merges remote branches into your current local branch, so pulling all remote branches is probably not what you want.

Marian Theisen
  • 6,100
  • 29
  • 39
1

Inspired by @cellofellow I added this to my .profile on Mac OS X:

function git-pull-all() {
    START=$(git symbolic-ref --short -q HEAD);
    for branch in $(git branch | sed 's/^.//'); do
        git checkout $branch;
        git pull ${1:-origin} $branch || break;
    done;
    git checkout $START;
};

function git-push-all() {
    git push --all ${1:-origin};
};

The main differences are:

  1. I am getting the current branch with git branch | grep '\*' | set 's/^.//' instead of git branch | grep '\*' | set 's/^.//'.

  2. You can supply a remote as a parameter e.g. git-pull-all origin. If you omit the parameter, it defaults to origin.

  3. Also added a similar shortcut to push multiple branches back the server.

Mike
  • 9,692
  • 6
  • 44
  • 61
1

If you only need the offline functionality, you can simple call git fetch -all to get all current information. Now you have all information at your disk and can work offline. Simple merge or checkout the branch you want to work on. Git pull is git fetch && git merge.

niels
  • 7,321
  • 2
  • 38
  • 58
0

You have to merge each branch individually. If you merged in multiple branches and more than one of them had merge conflicts, how could you possibly resolve then at the same time?

Gareth
  • 133,157
  • 36
  • 148
  • 157
  • Gareth - as I mentioned I use git for offline view only and there won't any conflicts. A git command or shell script might suffice my requirements. – Praveen Sripati Sep 27 '11 at 09:09