Lesson 6. How to fork a repo in GitHub Intro version control git
Learning objectives
At the end of this activity, you will:
- Be able to create a fork, or copy, of a GitHub repository within your Github account.
- Know how to navigate between your GitHub repository and a forked GitHub repository.
- Be able to explain how your forked repository relates to the original repository that it was created from.
What you need
- A GitHub user account
- A terminal running bash, and
- git installed and configured on your computer.
Follow the setup instructions here:
What is a fork?
A GitHub fork is a copy of a repository (repo) that sits in your account rather than the account from which you forked the data from. Once you have forked a repo, you own your forked copy. This means that you can edit the contents of your forked repository without impacting the parent repo.
An example forking workflow
In this workshop you will work from a central repo owned by Earth Lab. You will:
Fork
this repo owned by Earth Lab into your GitHub account.Clone
the fork of your repo, so you can edit the contents locally- Make edits to your local cloned copy of the repo on your computer
add
,commit
andpush
those edits back to your fork on GitHub- Suggest the changes that you made, to be added to the Earth Lab central repo using a
pull request
This workflow has a central repository - which is the one that Earth Lab owns. Everyone in the workshop will then contribute to the central repository. There are other Git and GitHub workflows too. However in this workshop, we are demonstrating a central repo workflow.
How to Fork a Repo
You can fork any repo by clicking the fork button in the upper right hand corner of a repo page.
Challenge: fork the Earth Lab 14ers repo
- Login to your GitHub account.
- Navigate to the
earthLab/14ers-git/
` repo. - Use the fork button to create your a fork of the
14ers-git
repo in your account.
Data tip: You can change the name of a forked repo and it will still be connected to the central repo from which it was forked. For now, leave it the same.
Explore your 14ers-git fork
Now, navigate to your new fork. Its name should be:
YOUR-USER-NAME/14ers-git.
Sometimes, navigating between repositories and keeping track of where you are on the GitHub website can be confusing. In this case note the URL. The Earth Lab central repo contains the earthlab
account name:
https://github.com/earthlab/14ers-git
and your forked repo contains your account name:
https://github.com/YOUR-USER-NAME/14ers-git
A good way to figure out which repo you are viewing is to look at the
- The name of the repo: does it contain your username? Or your colleagues? Or Earth Lab’s?
- Look at the path or URL to the repo and ask the same questions.
Your fork vs. the central repo
When you create a fork, it is an exact copy, or completely in sync with, the parent repo. You could confirm this by comparing your fork to the Earth Lab central repository using the pull request option. We will learn about pull requests in the next lesson
The fork will remain in sync with the central repo until:
- You modify your forked copy of the repo.
- The central repository is modified.
If you modify your forked repo, the changes will not be reflected in the central repo until you merge your fork with the central repo.
Summary workflow – fork a GitHub repository
On the github.com website:
- Navigate to desired repo that you want to fork.
- Click Fork button.
Additional resources
Important terms
- Central repo (on Earth Lab’s GitHub account ) - the main repo that everyone contributes to in the workshop. This is the “final working version” of the project.
- Your fork (on your GitHub account) - your working copy of the central repo stored in your GitHub account.
- Your repo clone (on your computer) - the local version of the fork in your GitHub account that lives on your computer. You will most often work locally on your computer and then push updates to GitHub.
Git resources
- Git Pro version 2 book by Scott Chacon and Ben Straub
- Learn about other version control workflows here. This includes using Bitbucket vs Github for git repo cloud hosting.
- Diagram of Git Commands – this diagram includes more commands than we will learn in this series but includes all that we use for our standard workflow.
- GitHub Help Learning Git resources
Leave a Comment