A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
Most commonly, forks are used to either propose changes to someone else's project or to use someone else's project as a starting point for your own idea.
Forking a repository is simple.
- On the top right corner of this project page, click Fork.
- That's it! You now have a copy of this project on your own profile.
- On GitHub, navigate to your fork of this project.
- Under the repository name, click Clone or download.
- In the clone with HTTPs section, click the icon to copy the URL for the repository.
- Open Terminal.
- Type
git clone
, and then paste the URL you copied. It will look like this, with your GitHub username instead ofYOUR-USERNAME
.
git clone https://github.com/YOUR-USERNAME/git-workshop
- Press Enter. Your local clone will be created.
It's good practice to regularly sync your fork with the original (upstream) repository.
- In your terminal, change directory into the project.
$ cd /Users/Enda/code/github.com/git-workshop
- Type
git remote -v
and press Enter. You will see the currently configured remote project on GitHub.
$ git remote -v
origin [email protected]:YOUR_USERNAME/git-workshop.git (fetch)
origin [email protected]:YOUR_USERNAME/git-workshop.git (push)
- We need to add the original project, known as the upstream, to our remotes.
$ git remote add upstream https://github.com/craicoverflow/git-workshop.git
-
Fetch the latest branches and commits. Commits to master will be stored in a local branch, called
upstream/master
. -
Checkout your local
master
branch.
$ git checkout master
> Switched to branch 'master'
- Merge the changes from
upstream/master
into your localmaster
branch. This brings your fork'smaster
branch into sync with the upstream repository.