Sub topic 4
Clone Your Fork
You have a fork on GitHub. This chapter copies it to your computer so you can edit files. It assumes you have a GitHub account, Git installed with your name and email configured, and basic comfort with add, commit, status, and log in a terminal. It also assumes you have already forked the repository.
What a clone is
A fork lives on GitHub's servers. A clone is a full copy of a repository on your own machine. It includes every file, the complete commit history, and a link back to the repository it came from.
Cloning does not create a new copy on GitHub. It only downloads. Your fork and your local clone are two separate copies, and you keep them aligned with git push and git pull.
Copy the clone URL
On your fork's page, click the green Code button. Choose HTTPS or SSH.
- HTTPS looks like
https://github.com/YOUR-USERNAME/REPO.git. It works everywhere, and GitHub asks for a personal access token instead of a password when you push. - SSH looks like
[email protected]:YOUR-USERNAME/REPO.git. It needs an SSH key registered with your account, but it does not prompt you on every push.
Use the URL of your fork, not the original repository. Cloning the original works for reading, but you cannot push to it.
Run the clone
git clone https://github.com/YOUR-USERNAME/REPO.git
cd REPOgit clone creates a folder named after the repository, downloads the history, and checks out the default branch, usually main. It also creates a remote named origin that points to the URL you cloned from.
Check what you got
Confirm the clone worked before you change anything.
git status
git log --oneline -5
git remote -vYou should see:
git statusreportsOn branch mainand a clean working tree.git logshows the project's most recent commits.git remote -vlistsoriginwith your fork's URL, once for fetch and once for push.
At this point only origin exists. The next chapter adds a second remote that points to the original project.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `repository not found` | Typo in the URL, or the fork is private and you are not signed in | Copy the URL again from your fork's page |
| `Permission denied (publickey)` | You used an SSH URL without a registered key | Add an SSH key to GitHub, or clone with HTTPS |
| `Authentication failed` over HTTPS | You entered your account password | Use a personal access token or a credential helper |
| `destination path 'REPO' already exists` | A folder with that name is already there | Move it, or give a folder name: `git clone URL my-folder` |
Large repositories
Some projects have long histories, and a full clone can take minutes. A shallow clone downloads only recent history:
git clone --depth 1 https://github.com/YOUR-USERNAME/REPO.gitThis is fine for a small documentation fix. A shallow clone has limited history, so commands like git log and git blame show less. Stay with a full clone if you are unsure.
Exercise
You cloned your fork and git remote -v shows origin pointing to https://github.com/ORIGINAL-OWNER/REPO.git. What went wrong, and what is the simplest fix?
Show answer
You cloned the original repository instead of your fork, so you cannot push to it. If you have made no changes, delete the folder and clone again using the URL from your fork's page, which contains your username. You could also change the URL with git remote set-url origin https://github.com/YOUR-USERNAME/REPO.git, but a fresh clone is simpler.
Exercise
After git clone, what does Git name the remote that points to your fork, and which branch is checked out?
Show answer
The remote is named origin. The checked-out branch is the repository's default branch, usually main.