10

双仓库同步代码

 3 years ago
source link: https://eelve.com/archives/doublegit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

前情提要】在最近的工作中,涉及到把一份代码同时上传到两个git仓库,下面是简单的记录。


壹、准备工作

分别在Github和Gitee平台上配置SSH公钥,便于使用git协议拉取和提交推送代码的时候需要输入密码。

贰、拉取代码

我这里以我的[email protected]:eelve/fly.git仓库为示例来说明。使用工具或者命令拉取[email protected]:eelve/fly.git

git clone [email protected]:eelve/fly.git

叁、修改配置文件

进入拉取的仓库文件夹下,找到.git的隐藏文件夹,打开config文件

[core]    repositoryformatversion = 0    filemode = false    bare = false    logallrefupdates = true    symlinks = false    ignorecase = true[submodule]    active = .[remote "origin"]    url = [email protected]:eelve/fly.git    fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"]    remote = origin    merge = refs/heads/master

修改成如下配置

[core]    repositoryformatversion = 0    filemode = false    bare = false    logallrefupdates = true    symlinks = false    ignorecase = true[submodule]    active = .[remote "origin"]    url = [email protected]:eelve/fly.git    fetch = +refs/heads/*:refs/remotes/origin/*    url = [email protected]:eelve/fly.git[branch "master"]    remote = origin    merge = refs/heads/master[remote "gitee"]    url = [email protected]:eelve/fly.git    fetch = +refs/heads/*:refs/remotes/github/*

添加一个remote远程仓库,并添加远程仓库地址,修改的部分如下

url = [email protected]:eelve/fly.git
[remote "gitee"]    url = [email protected]:eelve/fly.git    fetch = +refs/heads/*:refs/remotes/github/*

肆、推送测试

使用其他工具或者执行git push命令推送,我这里没有其他分支我这里就省略了分支名称等等

git push

然后查看gitee上面的仓库,可以看到,就已经成功推送上去了。

202004301
202004302

后面的话】完成上述工作之后,就能够做到一次推送,两个仓库都有代码了。


薏米笔记

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK