gitgithub

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


Solution

  • 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.