Git Fork: How to Fork a Repo and Open Your First PR
Table of Contents
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. It's also the standard way to contribute to open source: you don't need write access to someone's repo to fork it, change it, and offer your changes back.
All the content from our Boot.dev courses are available for free here on the blog. This one is the "Fork" chapter of Learn Git 2. If you want to try the far more immersive version of the course, do check it out!
What Is a Fork?
A fork is a copy of the original repository that lives in your account. It's yours: you can modify it, push to it, and generally mess it up however you like without affecting the original.
You may have noticed that there is no manual entry for git fork:

Why?
Forking is not a Git operation, but it is a feature offered by many Git hosting services such as GitHub, GitLab, and Bitbucket.
Those services "fork" a repo by creating a new copy of the repo and associating it as a "fork" of the original. It's quite literally just a copy that is linked to the original via some metadata.
If the line between Git (the tool) and GitHub (the service) is still fuzzy for you, read Git vs GitHub first.
How Do You Fork a Repo on GitHub?
Forking on GitHub is a button, not a command:
- Navigate to the repo you want to fork
- Press the "fork" button in the top right corner

- Pick a name (keeping the original name is usually the move), and leave the other settings as default

You'll be redirected to your new forked repo, which lives at github.com/your_username/repo_name.
If you prefer the terminal, the GitHub CLI can do the same thing with gh repo fork.
Fork vs Clone: What's the Difference?
Click to play video
A fork is a server-side copy: GitHub copies the repo into your account, and everything stays up on GitHub. A clone is a local copy: git clone downloads a repo to your machine so you can actually work on it.
They're not competing options, you typically do both. Say you're contributing to bootdotdev/megacorp, the fictional MegaCorp™ repo we use in the course. Fork it on GitHub, then clone your fork (not the original) to your local machine:
git clone https://github.com/your_username/megacorp
cd megacorp
git branch
# * main
Cloning your fork means your fork is the origin remote, so you can push to it freely. You couldn't do that with a clone of the original repo unless the owner gave you write access, and the owner will not give you write access.
Forks Aren't Branches Either
A branch is a lightweight pointer to a commit within a single repository, and creating one requires write access to that repo. A fork is an entire copy of the repository under your own account, no permission required.
| Branch | Fork | |
|---|---|---|
| Lives | Inside the same repo | In your account |
| Requires write access | Yes | No |
| Typical use | Feature work with your team | Contributing to someone else's repo |
On your own projects and at work, you'll use branches. When contributing to open source projects you don't own, you'll use a fork... and then branches inside your fork.
How to Contribute to Open Source with a Fork
When you fork someone's repository on a platform like GitHub, you get a copy of the repository in your account. This is the standard way to contribute to someone else's open-source project. The steps are typically:
- Fork their repo into your account
- Clone your fork to your local machine
- Create a new branch (let's call it
your_feature) - Make changes
- Commit and push changes to your fork's remote
your_featurebranch - Create a pull request to
original_owner/repomainfromyour_username/repoyour_feature
Then the original owner can review your changes. If they like them, they can merge the changes straight from your fork into their repository.
In practice, the local half of that workflow looks like this. Sticking with the megacorp example, say your change is adding yourself to the repo's contributors directory:
git switch -c add_contrib
git add contributors/your_username.txt
git commit -m "add myself as a contributor"
git push origin add_contrib
Then on GitHub, open a pull request from your_username/megacorp add_contrib into bootdotdev/megacorp main.
Once your pull request is merged (or closed), you don't need the feature branch anymore. Switch back to main and delete it:
git switch main
git branch -D add_contrib
-D is the shortcut for --delete --force.
Note: if the original repo moves forward while you're working on your branch, your pull request can fall behind and hit merge conflicts. Resolving those (plus rebase conflicts, squashing commits, and the rest of the team-workflow survival kit) is exactly what Learn Git 2 covers. If you're not yet comfortable with commits, branches, and remotes, start with Learn Git instead.
Frequently Asked Questions
Is fork a Git command?
No. There is no git fork command. Forking is a feature offered by Git hosting services like GitHub, GitLab, and Bitbucket, not a Git operation.
What is the difference between fork and clone?
A fork is a server-side copy of a repo into your hosting account. A clone is a local copy downloaded to your machine with git clone. You typically fork first, then clone your fork.
What is the difference between a fork and a branch?
A branch is a pointer within a single repository and requires write access to create. A fork is a full copy of the repository under your own account and requires no permission.
Do I need to fork a repo to contribute to open source?
If you don't have write access to the repo, yes. Fork it, push a feature branch to your fork, then open a pull request from your fork to the original repository.
What happens to the original repo when I change my fork?
Nothing. Your fork is an independent copy, so changes stay in your fork until the original owner merges a pull request from it.
