167

Here are steps of code contribution from the topic "How do I contribute to other's code in GitHub?"

  1. Fork the project
  2. Make one or more well commented and clean commits to the repository. You can make a new branch here if you are modifying more than one part or feature.
  3. Perform a pull request in github's web interface.

Is it possible to make a pull request without forking a repo?

It's quite sad to see more than 20 repos in my account which were forked for some pull requests. They have no activity then and zero stars / followers. Looks like I'm just copying somebody's code for a black day.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
Jasper
  • 5,090
  • 11
  • 34
  • 41

7 Answers7

174

If you don't have access to create branches on that repository, there is no way to create a pull request without forking.

sorin
  • 161,544
  • 178
  • 535
  • 806
Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • 19
    Can you please explain how you can create a pull request if you DO have access to branches on that repository? – bolinfest Dec 30 '14 at 19:43
  • 22
    GitHub has a good guide about that: https://help.github.com/articles/creating-a-pull-request/ – Ryan Bigg Jan 05 '15 at 03:29
  • 9
    Just a reminder for something that may not be as clear to everyone. You need to create a fork for every repository you contribute to... but creating branches in your fork allows you to work one more than one PR at once for the upstream repo. You don't need 20 forks from the same repo to contribute with 20 PRs. – JulioHM May 11 '19 at 03:42
  • 1
    "...If you don't have access to create branches ..." how to check if I can create branch on repo or not ? – vikramvi Feb 18 '21 at 13:03
  • @RyanBigg How do you create the pull request if you DO have access to create branches?? – Jason Kelley Sep 16 '21 at 22:06
  • @RyanBigg is linking to the article if you do have access. But that article opens with the line "If you want to create a new branch for your pull request and do not have write permissions to the repository, you can fork the repository first". This is just to notify. The rest of the article talks about a PR directly into the same repo. – Mike Williamson Dec 07 '21 at 12:13
  • 1
    Just to answer @JasonKelley's question in here: if you do have access to create branches on the repository, create a new branch, make your changes, go go to the PRs page, tap the button to make a new PR, and make a PR to the old branch from the new branch. Old branch will be on the left. – Mixchange Jan 08 '22 at 19:01
32

Once your pull requests are accepted, you can safely delete the repo.

Afterwards, simply clone directly from the original upstream repo.

If you have other pull requests to make, then you should make them in their own respective branch, which means you can safely delete the branch you made to manage an accepted pull request (as in "My pull request has been merged, what to do next?")

Semnodime
  • 1,872
  • 1
  • 15
  • 24
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    FYI, github recently added a button to merged pull requests to make it easy (and intuitive) to delete the pull request branch: https://github.com/blog/1335-tidying-up-after-pull-requests – David M Feb 11 '13 at 22:36
  • @DavidM They should add a feature to auto-delete the forked repo once that happens. – fuz Mar 25 '23 at 12:01
16

By definition, a pull request involves a fork unless you have commit access to the destination repository. You can do a couple of things, though:

  1. If you do have commit access, create a branch and make your pull request against the new branch.
  2. Post your patch in the body of an issue. This isn't really the GitHub way, but it certainly works.
  3. Fork a repository, create a pull request, and then delete the fork once the pull request is merged or declined.

If you're just trying to avoid keeping repositories around that you aren't actively using, I personally suggest option #3. It sticks to the accepted GitHub workflow without cluttering up your dashboard.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
  • Probably best put here: 4. Maintain a second Github account just to deal with these pull-request-and-forget scenarios. It won't matter if that account has 20 inactive repos in it, as it's not the main account. – tanius Mar 01 '19 at 14:20
  • 1
    "If you do have commit access, create a branch and make your pull request against the new branch." Ok, great. HOW? My god it's like pulling teeth trying to get an answer to this question. – Jason Kelley Sep 16 '21 at 22:04
7

github supports Shared Repository Model

The Shared Repository Model is more prevalent with small teams and organizations collaborating on private projects. Everyone is granted push access to a single shared repository and topic branches are used to isolate changes.

Pull requests are especially useful in the Fork & Pull Model because they provide a way to notify project maintainers about changes in your fork. However, they're also useful in the Shared Repository Model where they're used to initiate code review and general discussion about a set of changes before being merged into a mainline branch.

Community
  • 1
  • 1
Ya Zhuang
  • 4,652
  • 31
  • 40
1

You still need that one-liner: hub fork;git push -u $GIT_USER HEAD;hub pull-request

Anona112
  • 3,724
  • 4
  • 21
  • 30
0

This is confusing. You can create pull request but you instead fork someone project then upload your own and in your fork make changes. Select options to compare branches. This is one of method. You should fork someone project and clone it using newest git gui (type url and name of folder, installation path will store your forks, default setting should be optimal for pasting). Alternatively use soulseek (which works like server), torrents or chomikuj (althrough you need use there dziellacz to split open source files to 1MB to merge).

AnonA
  • 1
  • 3
0

As a workaround, you can create organization only for fork repos.

meetjaydeep
  • 1,752
  • 4
  • 25
  • 39