How to submit a pull request from a cloned repo?

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?


Solution 1:

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.

Solution 2:

If you're ok with installing another binary in your path, github has released a nice little tool called hub.

If you've cloned someone else's repo:

$ hub fork  # This creates a fork and adds your repo as a remote

$ git push YOUR_USER feature  # push the changes to your new remote

$ hub pull-request  # will open your browser