Git 切换其他人分支的两种方法

在开源项目的开发中,如果有人为你的项目贡献代码并发起了 pr,在 merge 前我们需要切换到发起 pr 者的分支检查。

方法1. 直接 Pull

这也是 GitHub 官方推荐的方法。

首先从 develop 分支创建新分支:

> git checkout -b reyoung-feature/recommendation_v2_api develop

然后 pull:

> git pull https://github.com/reyoung/Paddle.git feature/recommendation_v2_api

方法2. 创建远程仓库

首先创建远程仓库,命名为 yuyang

> git remote add yuyang https://github.com/reyoung/book

然后 fetch:

> git fetch yuyang
remote: Counting objects: 5, done.
remote: Total 5 (delta 2), reused 2 (delta 2), pack-reused 3
Unpacking objects: 100% (5/5), done.
From https://github.com/reyoung/book
 * [new branch]      develop                   -> yuyang/develop
 * [new branch]      feature/add_web_pages     -> yuyang/feature/add_web_pages
 * [new branch]      feature/fix_bug_in_math   -> yuyang/feature/fix_bug_in_math
 * [new branch]      feature/recommendation_v2 -> yuyang/feature/recommendation_v2
 * [new branch]      master                    -> yuyang/master

这时他的所有分支都被获取到,可以直接 checkout。

Zhao Li /
Published under (CC) BY-NC-SA in categories 杂谈  tagged with Git