【git】github 如何同步別人的倉庫
前言
假設你有兩個 Git 倉庫
,并希望同步它們,以便它們含有相同的內(nèi)容。
你必須要在 Git 中配置一個遠程服務器指向上游的倉庫地址,這樣你在 fork 中的更改才能同步到原始的倉庫里。這樣也能把原始倉庫中的變更同步到 fork 里。
第 1 步
打開終端,進入本地項目的工作目錄。
第 2 步
查看你的 fork 當前配置的遠程倉庫地址:
$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
第 3 步
指定當前 fork 將要同步的上游遠程倉庫地址:
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
第 4 步
驗證一下你剛指定的上游倉庫地址:
$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
第 5 步
從上游倉庫拉取分支及其對應的提交記錄。對于 master 的提交會保存在一個本地分支 upstream/master 里。
$ git fetch upstream
remote: Counting objects: 75, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 62 (delta 27), reused 44 (delta 9)
Unpacking objects: 100% (62/62), done.
From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
* [new branch] master -> upstream/master
第 6 步
簽出你的 fork 的本地 master 分支
$ git checkout master
Switched to branch ‘master’
第 7 步
把 upstream/master 中的變更合并到本地的 master 分支里。這樣你的 fork 的 master 分支就和上游倉庫同步了,也不會丟失本地的更改。文章來源:http://www.zghlxwxcb.cn/news/detail-695831.html
$ git merge upstream/master
Updating a422352..5fdff0f
Fast-forward
README | 9 — — — -
README.md | 7 ++++++
2 files changed, 7 insertions(+), 9 deletions(-)
delete mode 100644 README
create mode 100644 README.md
第 8 步
把更改推送到服務器:文章來源地址http://www.zghlxwxcb.cn/news/detail-695831.html
$ git push
到了這里,關于【git】github 如何同步別人的倉庫的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!