Thursday, August 29, 2013

HOW TO: Switch a cloned Git repo to your fork

Here we go, yo, so what's the scenario?

You clone a Git repository from, say, GitHub, to dive into the source code.  Eventually, you decide you would like to make some changes and submit a pull request.  You need to switch your repo to point to your fork. Here's how.

List the current remote(s)

Here we see I cloned the Jenkins project, which was itself forked from Kohsuke's account.

$ git remote --verbose
origin https://github.com/jenkinsci/jenkins.git (fetch)
origin https://github.com/jenkinsci/jenkins.git (push)
upstream https://github.com/kohsuke/hudson.git (fetch)
upstream https://github.com/kohsuke/hudson.git (push)

Replace the existing origin with your fork


$ git remote rm origin
$ git remote add origin https://github.com/olivierdagenais/jenkins.git

Replace the existing upstream with the old origin

...if applicable, of course.

$ git remote rm upstream
$ git remote add upstream https://github.com/jenkinsci/jenkins.git

Double-check the remote(s)


$ git remote --verbose
origin https://github.com/olivierdagenais/jenkins.git (fetch)
origin https://github.com/olivierdagenais/jenkins.git (push)
upstream https://github.com/jenkinsci/jenkins.git (fetch)
upstream https://github.com/jenkinsci/jenkins.git (push)

No comments: