聆听风声 点点滴滴都很珍贵!

git提交到多个远程仓库


如果我的代码在一下两个仓库中,我修改了代码需要进行分别提交的话,那样操作麻烦不说,还会影响工作效率。我们修改配置文件让git可以达到一次操作想两个仓库提交代码 tp5的学习 - https://gitee.com/codeinfo1/tp5.git - https://github.com/gzwawj/tp5.git 在项目路径下打开git 添加remote,这里使用的是all 添加一个仓库地址

git remote add all https://gitee.com/codeinfo1/tp5.git

再添加一个仓库地址

git remote set-url --add all https://github.com/gzwawj/tp5.git

在操作完上面的添加命令后,打开.git/config配置文件

配置文件内容如下:
[remote "all"]
    url = https://gitee.com/codeinfo1/tp5.git
    fetch = +refs/heads/*:refs/remotes/all/*
    url = https://github.com/gzwawj/tp5.git

通过查看文件发现,我们可以直接修改配置文件

[remote "all"]
    url = https://gitee.com/codeinfo1/tp5.git
    url = https://github.com/gzwawj/tp5.git

有多少个远程库,就配置多少个url,并且去掉了fetch配置

进行提交测试
git push all --all
运行结果
D:\tp5>git push all --all
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 317 bytes | 317.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Powered by Gitee.com
To https://gitee.com/codeinfo1/tp5.git
   e906719..0832462  master -> master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 317 bytes | 317.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/gzwawj/tp5.git
   e906719..0832462  master -> master
D:\tp5>

可以看出代码提交了两次


Similar Posts

Comments