How to submit a pull request from a cloned repo?

Ben Hutchison picture Ben Hutchison · Feb 16, 2013 · Viewed 14k times · Source

How to submit a pull request from an existing locally-cloned repo?

Often, I want to look at some libraries source code from github, so I clone it. Later, I discover some issue with the code and raise it on a mailing list, often in passing. The library author says "nice find, can you send a pull request?".

And the answer is "not that easily". I haven't forked the repo yet, Ive cloned it. And there doesn't seem a way I can find to submit a pull request from a cloned repo?

If this limit is true, it feels like the sensible reaction is to fork anything and everything you ever look at, just so that if you ever might want to contribute, you can. And that fills up your github account with many inactive forks.

Doesn't seem a lot of talk about this issue - am I the only person whom this problem affects?

Answer

bobthecow picture bobthecow · Feb 16, 2013

Fork the repo on GitHub, then add your fork repo as a remote to your local cloned copy:

git remote add myfork https://github.com/<myGitHubAccountName>/<repoName>.git

Then you can push to your fork:

git push myfork master

If you're doing more than just this one pull request, you can remove the origin remote and name your fork as origin:

git remote rm origin
git remote add origin https://github.com/<myGitHubAccountName>/<repoName>.git

This is typically what I do. Sometimes I add the original origin as upstream so I still have a reference to it.