拷贝jira的bitbucket里项目下所有git到另一个项目里

2022-01-12
1分钟阅读时长

使用Atlassian的协作开发工具,在大公司开发项目中,有时候会在兄弟部门的项目上进行二次开发,但又不能对原来的项目的代码仓库有影响,往往需要独立fork一份项目出来,然后有时候公司不允许fork,于是涉及从一个项目里的所有git仓库迁移到新项目

第一种方式(推荐)

1. 批量克隆所有项目的git

mkdir program;cd program
echo -e "https://tt.abc.com/scm/gyd-glodonfmbim/gfm-ee.git\nhttps://tt.abc.com/scm/gyd-glodonfmbim/gfm-ff.git||xargs -P 6 -I {} git clone {}

2. 修改引用地址,批量push项目到远程项目

old="旧的origin地址"
new="新的origin地址"
cd program;
curDir=$PWD
for repo in *;do
    sed -ibak -e "s@$old@$new@" .git/config
    cd $curDir/$repo
    #建立仓库索引
    for i in `git branch -a | grep remote | grep -v HEAD | grep -v master`; do git branch --track ${i#remotes/origin/} $i; done
    echo "push all refs/tags "
#推送所有git工程到远程
    git push --all -u origin
done

第二种方式

更简单,需要经过额外操作,可以看到本地的源代码

1. 以mirror方式批量克隆所有项目的git

注意该方式克隆的仓库,看不到源代码,只有bare(裸)仓库,相当于.git里面的所有内容

mkdir program;cd program
echo -e "https://tt.abc.com/scm/gyd-glodonfmbim/gfm-ee.git\nhttps://tt.abc.com/scm/gyd-glodonfmbim/gfm-ff.git||xargs -P 6 -I {} git clone --mirror {}

2. 以mirror方式批量推送所有仓库到远程新项目

old="旧的origin地址"
new="新的origin地址"
cd program;
curDir=$PWD
for repo in *;do
    sed -ibak -e "s@$old@$new@" .git/config
    cd $curDir/$repo
    #建立仓库索引
    echo "push all refs/tags "
    #推送所有git工程到远程
    git push --mirror -u origin
done