由于在国内开发环境的特殊愿意,github经常拉取很慢,有时候我们直接就gitee复制github的项目来解决速度的问题,但是这和fork不一样,属于新建了一个分支,如果github的原项目更新,后续我们的库也要更新,如果使用gitee的同步工具很容易把之前的更改覆盖掉。
那有没有办法关联gitbub的分支呢?接下来尝试解决这个问题。
以这个项目https://github.com/pdliuw/ai_barcode.git为例。


创建成功后,进入项目管理,我们还是可以看到之前copy的项目地址。

回到我们的问题。
打开Android studio,从gitee拉取项目。点击Android studio的顶部工具栏git -》manage remote

我们可以看到只有一个gitee的远程项目,将我们的github项目添加进去,并命名为github

我们也可以通过命令进行添加
git remote add origin ******
git remote add github ******
使用git remote -v查看是否添加成功。
git remote -v

这里为了保险起见,本地也创建一个github分支,用来专门合并来自远程github项目的更新,防止我们更改的代码冲突造成问题。
关联远程分支
git remote add github git@github.com:pdliuw/ai_barcode.git
androidstudio 是看不到.git目录的,所以进入项目文件,打开.git下面的config文件夹


可以看到目前,remote信息是对的,但是branch并没有我们创建的github,关闭项目重新打卡,如果还是没有,可以手动添加如下信息:
[branch "github"]
remote = github
merge = refs/heads/github
进入github本地分支,刷新好之后,remote出现了github,则是成功了。

查看git 的console窗口,也是打印了相关信息

选择对应的远程分支就可以方便查看更新了

合并远程分支更新到本地

大功告成。
网友评论