How to submit a pull request from a cloned repo?

GithubPull Request

Github Problem Overview


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?

Github Solutions


Solution 1 - Github

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 - Github

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

Solution 3 - Github

I always clone instead of fork as well and the following steps work for me:

  1. Create a new branch on your cloned repo and make the new change.

  2. Push the change to your branch as the following:

    git push origin insert_your_working_branch_name

  3. Now you should be able to find your working branch in pull request from github master.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen HutchisonView Question on Stackoverflow
Solution 1 - GithubbobthecowView Answer on Stackoverflow
Solution 2 - GithubrdreyView Answer on Stackoverflow
Solution 3 - GithubohmyanView Answer on Stackoverflow