Your first open source contribution starts with a question: do I clone this repo or fork it? Usually both. They do different jobs, and mixing them up is how people end up with broken remotes and pull requests that go nowhere.The one-sentence difference. Clone is a Git command. git clone copies a repository, with its full history, onto your machine. Fork is not a Git command. It’s a GitHub (or GitLab) feature that copies a repository into your own account on the server. Why fork at all? You can’t push to a repo you don’t have write access to. Cloning someone else’s project gets the code onto your laptop, but your push will be rejected. A fork gives you a copy you can push to. A pull request is how you ask the original maintainers to pull your changes in. Three places, three names. original repo ("upstream") │ click Fork on GitHub ▼ your fork ("origin") ◀──── git push ────┐ │ git clone │ ▼ │ your computer (local) ── commit on a branch ─┘ your fork ── Pull Request ──▶ original repo The full workflow # 1. Fork on GitHub, then clone YOUR fork (check your username is in the URL) git clone https://github.com/YOUR-USERNAME/project.git cd project # 2. Point a second remote at the original git remote add upstream https://github.com/original-owner/project.git git remote -v # origin = your fork, upstream = the original # 3. Work on a branch, never directly on main git checkout -b fix-typo-in-readme git add . git commit -m "Fix typo in README" # 4. Push to YOUR fork, then open a pull request on GitHub git push origin fix-typo-in-readme Shortcut: with the GitHub CLI, gh repo fork owner/project --clone does the fork, the clone, and sets origin and upstream for you. Forks don’t update themselves. Once you fork, your copy is frozen at that moment. If the original moves on, you have to sync it, and there are three ways: Click Sync fork on your fork’s page on GitHub. Run gh repo sync YOUR-USERNAME/project -b main. Use plain Git: git fetch upstream git checkout main git merge upstream/main git push origin main Sync before you start new work so your pull request doesn’t conflict with changes you didn’t know about.Which one do you need? Situation Use Your own repo, or a team repo where you have write access Clone Contributing to a project you can’t push to Fork, then clone your fork Just reading or running someone’s code locally Clone Taking a project in your own direction Fork Forks are bigger than pull requests. Forking is also how communities protect themselves. When Terraform’s license changed in 2023, the community forked its last open version into OpenTofu. When Redis changed licenses in 2024, the Linux Foundation backed Valkey. Both forks now have their own governance and keep their open licenses. That connects to last week. A fork carries the original’s license with it. Your fork of an MIT project is still bound by the MIT notice, and a fork of a GPL project must stay GPL if you distribute it.Common Mistakes Cloning the original instead of your fork. Check the username in the URL. Committing straight to main on your fork. Branch for every change. Forgetting upstream. Without it you can’t sync. Assuming the fork updates automatically. It doesn’t. Further reading: GitHub Docs: “Fork a repo” and “Syncing a fork.”
Git Clone vs Fork: Stop Mixing Them Up
Full Article
Original Source
Read the full article at Hackernoon →KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.