-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-clone-batch.sh
executable file
·51 lines (47 loc) · 1.1 KB
/
git-clone-batch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
#if there are many repository at current directory,
#this script clones each repository to designated target directory.
#first arg is target directory where new repository will be cloned
#Check number of arguments
if [ $# != 1 ]
then
echo "Usage: input an argument";
exit;
fi;
#Check target directory is valid
if [ -d $1 ]
then
echo "target directory exist"
else
echo "Error: target directory does not exist.";
exit 0;
fi;
#cwd=${PWD##*/}
cwd=$PWD
echo "Current direcotry is $cwd"
for repo in *
do
if [ -d $repo ] && [ -e $repo/.git ]
then
echo "$repo is git repository to be cloned #########";
target="$1/$repo";
echo "git clone $repo $target";
date;
cd $cwd;
git clone $repo $target;
echo "Git purging new repository, $target";
cd $target
pwd;
du -d1 -h
git reset --hard
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --aggressive --prune=now
du -d1 -h
date;
echo "";
cd $cwd
else
echo "* $repo will not be cloned.";
fi;
done;