Thursday, May 07, 2015

Clone all your git repositories over ssh with one small script

I worked on this with my colleague Rivo. Usefull when you have many projects (and many repos!)

#!/bin/bash
# Don't forget to install sshpass -> sudo apt-get install sshpass

HOST=[your_server]
USERNAME=[account]
PASSWORD=[password]
ROOT_PATH=[path_of_your_repos_on_server_as_/opt/git] 
PROJECTS=`sshpass -p "$PASSWORD" ssh $USERNAME@$HOST ls -d $ROOT_PATH/*.git | sed -r 's/^.+\///' | sed -r 's/\.git//'`

for prj in $PROJECTS
  do
    rm -rf $prj
    sshpass -p "$PASSWORD" git clone ssh://$USERNAME@$HOST/$ROOT_PATH/$prj.git
  done
exit

1 comment:

simashree said...

Thanks for the great information in your blog Selenium Training in Chennai