Fork a Repo and fetch

Table of Contents

1 如果我们Fork一个源码库后,如何继续从原源码库更新呢?

2 Fork "Spoon-Knife" 库

在其页面按“Fork”按钮

3 Clone自己的库

git clone https://github.com/username/Spoon-Knife.git
# Clones your fork of the repo into the current directory in terminal

4 配置远端库

当一个源码库被拷贝到本地后,它默认的远端库是#origin#,并不是那个fork前的原源码库,为了继续更新原源码库,我们需要把原源码库加入进来,并命名为#upstream#

cd Spoon-Knife
# Changes the active directory in the prompt to the newly cloned "Spoon-Knife" directory

git remote add upstream https://github.com/octocat/Spoon-Knife.git
# Assigns the original repo to a remote called "upstream"

git fetch upstream
# Pulls in changes not present in your local repository, without modifying your files

5 推送更新

git push origin master
# Pushes commits to your remote repo stored on GitHub

6 从原源码库更新修改

git fetch upstream
# Fetches any new changes from the original repo

git merge upstream/master
# Merges any changes fetched into your working files

7 其他相关命令

  • 显示所有的远程仓库
$: git remote -v

加上 -v 选项(此为 –verbose 的简写取首字母)显示对应的克隆地址

  • 重命名远程仓库
$: git remote rename oldname newname
  • 删除远程仓库
$: git remote rm name
  • 查看远程仓库信息,可用于跟踪别人的push
$: git remote show remotename

Footnotes:

Author: Shi Shougang

Created: 2015-03-05 Thu 23:19

Emacs 24.3.1 (Org mode 8.2.10)

Validate