227

I'd like to know the differences between doing a Fork of a project and doing a clone of it.

Can I only send pull requests via GitHub if I've forked a project?

3
  • 3
    Possible duplicate of Are git forks actually git clones?
    – j08691
    Commented Jun 2, 2017 at 17:01
  • 9
    For people who land here looking for an explanation of "fork" with Git (not GitHub). There is no "fork" command on Git. It is more a GitHub (not Git), concept. A distinction easily forgotten.
    – ambassallo
    Commented Dec 5, 2019 at 13:07
  • 1
    Thanks, @ambassallo, that should be delineated in the opening sentence of an answer to this question. Commented Jan 26 at 3:56

11 Answers 11

161

When you say you are Forking a repository you are basically creating a copy of the repository under your GitHub ID. The main point to note here is that any changes made to the original repository will be reflected back to your forked repositories(you need to fetch and rebase). However, if you make any changes to your forked repository you will have to explicitly create a pull request to the original repository. If your pull request is approved by the administrator of the original repository, then your changes will be committed/merged with the existing original code-base. Until then, your changes will be reflected only in the copy you forked.

In short:

The Fork & Pull Model lets anyone fork an existing repository and push changes to their personal fork without requiring access be granted to the source repository. The changes must then be pulled into the source repository by the project maintainer.

Note that after forking you can clone your repository (the one under your name) locally on your machine. Make changes in it and push it to your forked repository. However, to reflect your changes in the original repository your pull request must be approved.

Couple of other interesting dicussions -

Are git forks actually git clones?

How do I update a GitHub forked repository?

6
  • 38
    "The main point to note here is that any changes made to the original repository will be reflected back to your forked repositories." That's a bit misleading I think. AFAIK, changes made to the original repository after the fork are not automatically reflected in the fork; you have to move those changes manually. Changes that happened before the fork though are copied to the new fork when you click the fork button.
    – Ajedi32
    Commented Sep 11, 2015 at 13:30
  • 1
    " any changes made to the original repository will be reflected back to your forked repositories"..really?? Not automatically I hope Commented Feb 16, 2018 at 2:00
  • I was working for a client's project and using cloning and push model for work. One day i forked it and i immediately got a message saying what is the need to fork the complete repo. I really don't understand how is that considered wrong? Commented Apr 10, 2018 at 7:08
  • changes made to the original repository after the fork are not automatically reflected in the fork, but in order to do so, check the step 3 of this blog :- help.github.com/articles/fork-a-repo Commented Jul 5, 2018 at 16:34
  • 2
    This sounds just like cloning.
    – GenDemo
    Commented Dec 18, 2022 at 22:16
126

Basically, yes. A fork is just a request for GitHub to clone the project and registers it under your username; GitHub also keeps track of the relationship between the two repositories, so you can visualize the commits and pulls between the two projects (and other forks).

You can still request that people pull from your cloned repository, even if you don't use fork -- but you'd have to deal with making it publicly available yourself. Or send the developers patches (see git format-patch) that they can apply to their trees.

3
  • 7
    Forks take a lot more work to update than clones. A clone can be updated with a simple git pull. A fork takes multiple commands. And not surprising, nearly every fork I look at is out-of-date. Forks are like the Maven repository problem on steroids. Instead of one out of date repo (Maven), there's thousands of them (Git).
    – jww
    Commented Feb 12, 2017 at 6:13
  • 2
    @jww sounds like its best to just stick with clone - why use fork then ?
    – serup
    Commented Jan 16, 2019 at 11:55
  • 2
    @serup - the reason being is the forked copy can be git pulled in so there is still some sort of relationship that exists. If you cloned the entire copy its sitting on your own local machine and disconnected from the original repo.
    – JonH
    Commented Feb 8, 2019 at 16:34
40
  • Forked project is on your online repository (repo).
  • Cloned project is on your local machine (I usually clone after forking the repo).

You can commit on your online repo (or commit on your local repo and then push to your online repo), then send pull request.

Project manager can accept it to get your changes in his main online version.

0
13

A clone is where you have proper duplication, and separation between, two (possibly different) versions of a repository. When one repo is amended, the new content must be actively copied to the other repo using a push command. And changes in the other repo fetched.

When you fork a repo, on a server, there is no need for duplication of content because both repos will use the same [fixed object] content from that same server. The 'trick' is in managing the different user viewpoints so that each user believes they have a full personal copy of the repo. Pushes and fetches between forks is simply updates the user's pointers.

At a lower level, git does the same thing internally. If you have three different files, each containing Hello World, then git simply 'forks' its single copy of the Hello World blob and offers it up in each of the three places as required.

The ability to fork on the server means that Github's large storage allowance isn't that big on average as every body shares the one single underlying repo.

6

While @AniketThakur's answer is very good. No one has answered the following question yet.

Can I only send pull requests via GitHub if I've forked a project?

No. If you are a contributor to a repository, you can: Make a local clone. Make a local branch. Add commits to that branch. Push the local branch back to github (creating a remote branch in the process). Make a pull request requesting for that branch to be merged into the master branch (or whatever branch you like).

5

In a nutshell, Forking is perhaps the same as "cloning under your GitHub ID/profile". A fork is anytime better than a clone, with a few exceptions, obviously. The forked repository is always being monitored/compared with the original repository unlike a cloned repository. That enables you to track the changes, initiate pull requests and also manually sync the changes made in the original repository with your forked one.

3

In case you did what the questioner hinted at (forgot to fork and just locally cloned a repo, made changes and now need to issue a pull request) you can get back on track:

  1. fork the repo you want to send pull request to
  2. push your local changes to your remote
  3. issue pull request
3

In a nutshell, "fork" creates a copy of the project hosted on your own GitHub account.

"Clone" uses git software on your computer to download the source code and it's entire version history unto that computer

2

Another weird subtle difference on GitHub is that changes to forks are not counted in your activity log until your changes are pulled into the original repo. What's more, to change a fork into a proper clone, you have to contact Github support, apparently.

From Why are my contributions not showing up:

Commit was made in a fork

Commits made in a fork will not count toward your contributions. To make them count, you must do one of the following:

Open a pull request to have your changes merged into the parent repository. To detach the fork and turn it into a standalone repository on GitHub, contact GitHub Support. If the fork has forks of its own, let support know if the forks should move with your repository into a new network or remain in the current network. For more information, see "About forks."

0

Why Forks?

Forking, where a repo of the original is created in your own GitHub account is a lot more secure for the original and keeps the original repo a lot cleaner, ie: with a forked branch your dev branches don't show up in the original repo and any sandbox work that you do can't affect the original in any way so you can work and play around with the code as much as you want without any worry of messing something up. It also allows the original repo to remain very locked down for security reasons. The forked repo can still easily be kept up to date with the original branch, if fact, its imperative that you do so and that any/all PRs be updated before creating the PR. Once a PR is created you can still update it with any changes, but it allows you to see a snapshot of what the current changes look like compared to production. Sometimes devs with create a PR before the work on a dev/feature branch even begins so they can see a snapshot at any time just by pushing their most recent changes to their own Forked repo working branch, that then updates the view in the PR.

When you have something to submit for consideration in the production version you then do a Pull Request into a specific branch in the original. That could be into a "merge" branch that I an exact duplicate of what's in production ( master/main ) or it may be more of a staging branch. My suggestion is that PRs never be done into master/main directly. It's gonna need to be tested and tested and tested before it gets into master. Personally, I never merge into master until it's been in production long enough to be considered stabilized. This is what I usually do:

Forked repo -> dev branch -> PR into a merge branch -> test branch -> staging branch -> deploy branch -> after the changes are stabilized in production then -> master.

0

If you would like to make changes directly to a repository you have the permission to contribute to, then cloning will be the first step before we implement the actual changes and push. If you don't have permissions to contribute to the repository, but would like to implement changes anyway, a fork is the way to go.

Not the answer you're looking for? Browse other questions tagged or ask your own question.