迁移仓库:包括所有分支,tag等…
一、迁移一个Git仓库
把一个git仓库迁移到另外一个git仓库,含所有的分支,标签,历史记录,日志
git clone --mirror <URL to my OLD repo location>
cd <New directory where your OLD repo was cloned>
git remote set-url origin <URL to my NEW repo location>
git push -f origin
二、批量迁移仓库
move.sh文件
#!/bin/bash
filename=$1
IFS=$'\n\n'
for line in `cat $filename`
do
# echo $line
OLD_IFS="$IFS"
IFS=";"
array=($line)
IFS="$OLD_IFS"
old_origin=${array[0]}
new_origin=${array[1]}
echo "old origin: ${old_origin}"
echo "new origin: ${new_origin}"
mkdir workdir
sup_path=`pwd`
cd workdir
path=`pwd`
echo "开始clone项目..."
git clone --mirror $old_origin
echo "clone项目完毕."
for dir in `ls .`
do
if [ -d $dir ]
then
echo "项目目录: $dir"
cd $dir
echo "修改项目origin url..."
git remote set-url origin $new_origin
echo "开始推送新仓库..."
git push -f origin
echo "推送完毕."
fi
done
rm -rf $path
cd $sup_path
echo "done"
done
data.txt文件
.txt文件里面:每一行是一条记录
旧的git仓库地址,分号,新的仓库地址
<旧的git仓库地址>;<新的git仓库地址>
<旧的git仓库地址>;<新的git仓库地址>
<旧的git仓库地址>;<新的git仓库地址>
执行命令
bash move.sh data.txt