Cloning and Forking
Cloning: Download a Copy
git clone https://github.com/username/project.git
cd project
This gives you:
- The complete code
- The full commit history
- A connection back to the original (called
origin)
Forking: Your Own Copy on GitHub
A fork creates a copy of someone else's repo under your GitHub account. This is how you contribute to projects you don't own.
Fork Workflow
- Fork the repo on GitHub (click the Fork button)
- Clone your fork to your computer
- Make changes and commit
- Push to your fork
- Open a Pull Request to the original repo
# Clone YOUR fork (not the original)
git clone https://github.com/YOUR-USERNAME/project.git
cd projectMake changes
echo "My contribution" >> file.txt
git add .
git commit -m "Add my contribution"Push to YOUR fork
git push origin mainThen open a Pull Request on GitHub
Clone vs Fork
| Action | Clone | Fork |
|---|---|---|
| Creates a copy | On your computer | On your GitHub |
| Requires permission to push | Yes (to original) | No (it's yours) |
| Used for | Your own projects or team repos | Contributing to others' projects |
Keeping Your Fork Updated
# Add the original repo as "upstream"
git remote add upstream https://github.com/ORIGINAL/project.gitPull latest from original
git pull upstream mainPush to your fork
git push origin main
Summary
| Concept | Purpose |
|---|---|
git clone | Download a repo to your computer |
| Fork (GitHub) | Copy a repo to your GitHub account |
| Pull Request | Propose changes to original repo |
| upstream | Link to the original repo |