threads / discuss / 21694

Help creating script that mass-pulls Git(Hub) repos

Subject: Help creating script that mass-pulls Git(Hub) repos

## tl;dr

2 messages between Nov 21, 2009 and Nov 21, 2009.

replies: 1people: 2as markdown or json

Tony Maserati· Nov 21, 2009, 10:25 UTC · lore
Hi,

I got a bunch of repos I've cloned off GitHub and I'm looking for the best way to keep them all up to date.

I got a working zsh script, but it lacks some stuff. For instance I think it'd be neat if it could output the difference between the commit dates as oppose to those long hashes. And if it could initiate the pull only when necessary. Other ideas are welcome.

Does anybody have any suggestions to how I might complete or otherwise improve the below scripts? Thanks in advance.

Here's the working version:
abletony84$ cat pull_all.sh
#!/usr/bin/env zsh
for folder in $PWD/**/.git(:h); do
  cd $folder
  git pull
done
-
This script lacks a proper if clause, and shows hashes instead of dates:
abletony84$ cat pull_all2.sh
#!/usr/bin/env zsh
for folder in $PWD/**/.git(:h); do
  cd $folder
  if this repo needs an update; then # git ls-remote has been suggested
    old=$(git rev-parse HEAD)
    git pull >& /dev/null
    new=$(git rev-parse HEAD)
    echo "$folder: $old -> $new"
  else
    echo "$folder: nothing to do"
  fi
done
-
A slightly different approach, even more incomplete than the previous:
abletony84$ cat pull_all3.sh
#!/usr/bin/env zsh
for folder in $PWD/**/.git(:h); do
  cd $folder
  if repo still exists at github; then
    git fetch >& /dev/null
    if a merge is needed; then
      git merge >& /dev/null
      echo "$folder: date_of_last_current_commit -> date_of_last_new_comit"
    else
      echo "$folder: nothing to do"
    fi
  fi
done
-
Thanks again!
Tony
Kumar Appaiah· Nov 21, 2009, 15:18 UTC · re: Tony Maserati · lore

Re: Help creating script that mass-pulls Git(Hub) repos

On Sat, Nov 21, 2009 at 11:25:20AM +0100, Tony Maserati wrote:
> Hi,
> 
> I got a bunch of repos I've cloned off GitHub and I'm looking for the
> best way to keep them all up to date.
Would mr help?
http://kitenet.net/~joey/code/mr/
Kumar
-- 
Kumar Appaiah

← back to recent threads