ClickThisNick
ClickThisNick

Reputation: 5250

Checkout forked branch of repo without cloning fork

I like to do github code reviews, by checking out the code locally in my IDE.

If someone forks a github repo and submits a pull request, is there a way for me to checkout their code without cloning their public forked repo?

my-repo - I usually just git checkout branch

my-repo-forked - Here I need to git clone my-repo-forked and then git checkout branch

Upvotes: 4

Views: 1390

Answers (2)

Melroy van den Berg
Melroy van den Berg

Reputation: 3225

I believe this is the way:

git fetch origin pull/<PR_ID>/head:<BRANCH_NAME>
git switch BRANCH_NAME

Where you <BRANCH_NAME> can be any local branch name you want to give it.

Docs: GitHub.com Docs Checking out pull requests locally

Upvotes: 1

Mehdi
Mehdi

Reputation: 7413

You may add the forked repository as a second remote to your local repo:

cd my-repo
git remote add forked-version [fork-url-here]
git fetch forked-version
git checkout [branch-name-here]

This way, you only have one local git for both your original repository and the fork.

More information about remotes can be found in the Pro Git Book: 2.5 - Git Basics - Working with Remotes.

Upvotes: 5

Related Questions