2017-12-27 How to sysnchronize code from GitHub to gitee

1、 Import project from github to gitee

場景:備份GitHub代碼倉庫到國內倉庫gitee.com php

目的: 當GitHub沒法訪問時,可以訪問國內倉庫國內倉庫gitee.comhtml

Solution: android

Login In https://gitee.com/, use '"Import Respository"' to import project from github to gitee.git

https Respository

List all project form GitHub. Then choose to import project.
https Respositorygithub

Wait for a minute, import successfully.
https Respositoryfetch

2、Sysnchronize project code from GitHub to gitee

Scenario:When Github android-art-res.git code updated,how to sysnchronize code to gitee ?this

Solution 1: Use gitee fresh button.

Sample:
https://gitee.com/YingVickyCao/android-art-res.git
https://gitee.com/YingVickyCao/android-art-res.giturl

In gitee project page,Click 'fresh' button, force sysnchronizing from github project.
Wait for a minute, sysnchronize successfully.spa

https Respository

Solution 2: Use git push command

Sample:
git@gitee.com:YingVickyCao/android-about-demos.git
git@github.com:YingVickyCao/android-about-demos.git.net

Use git push both command

# In terminal,cd project dir. 

# 添加一個名爲 both 的遠端
$git remote add both git@gitee.com:YingVickyCao/android-about-demos.git

# 爲其添加 push 到 gitee.com 的 SSH 地址
$git remote set-url --add --push both git@gitee.com:YingVickyCao/android-about-demos.git

# 爲其添加 push 到 GitHub 的 SSH 地址
$git remote set-url --add --push both git@github.com:YingVickyCao/android-about-demos.git

#查看當前遠端倉庫
$git remote -v 
both    git@gitee.com:YingVickyCao/android-about-demos.git (fetch)
both    git@gitee.com:YingVickyCao/android-about-demos.git (push)
both    git@github.com:YingVickyCao/android-about-demos.git (push)
origin    git@github.com:YingVickyCao/android-about-demos.git (fetch)
origin    git@github.com:YingVickyCao/android-about-demos.git (push)

In project .git/config file, we can "both" add successfully.
.git/config

# modify code 
$ git add .
$ git commit -m "test code"

$ git push both
Warning: Permanently added the RSA host key for IP address '192.30.255.112' to the list of known hosts.

git push both Warning

What this Warning means?

警告:爲IP地址192.30.255.112的主機(RSA鏈接的)持久添加到hosts文件中

192.30.255.112 是什麼地址?
http://www.ip.cn/index.php?
check ip

Add IP address '192.30.255.112' to the list of known '/etc/hosts'

  • backup /etc/hosts first.
  • Copy /etc/hosts, and then add it.

IP address to hosts

  • Overwrite /etc/hosts.

PS:

  • 使用git push origin both,能夠push到origin的多個url地址.
  • 使用git pull時,只能拉取origin裏的一個url地址(即fetch-url,如上圖),這個fetch-url默認爲添加的到origin的第一個地址。
    Git push pull error

若是更改,只須要更改config文件裏,那三個url的順序便可,fetch-url會直接對應排行第一的那個utl鏈接。

Reference

TBD

No.

結束語

感謝Reference中各位做者的無私貢獻.

歡迎你們留言、指點、交流。

相關文章
相關標籤/搜索