A fork is a copy of another repository under your account that stays linked to its original, the upstream: GitHub 29 shows how far the two have drifted and lets pull requests flow from the fork back to it. You cannot fork your own repository, so Sam practices on GitHub's own exercise repository, octocat/Spoon-Knife (about 14,000 stars and 160,000 forks), naming his copy so that it sits with his BookNest repositories:
gh repo fork octocat/Spoon-Knife --fork-name booknest-fork-spoon-knife --default-branch-only --clone
cd booknest-fork-spoon-knife
git remote set-url --push upstream no_push
git remote -v
gh repo set-default binarybehemoth/booknest-fork-spoon-knifehttps://github.com/binarybehemoth/booknest-fork-spoon-knife Cloning into 'booknest-fork-spoon-knife'... ... origin https://github.com/binarybehemoth/booknest-fork-spoon-knife.git (fetch) origin https://github.com/binarybehemoth/booknest-fork-spoon-knife.git (push) upstream https://github.com/octocat/Spoon-Knife.git (fetch) upstream no_push (push)
gh 29 repo fork --clone clones the fork as origin and adds the original as upstream (with plain Git 1,932 : git remote add upstream <url>); --default-branch-only copies just main. Two safety habits follow: a bogus upstream push URL makes a slip like git push upstream fail locally, and gh repo set-default stops gh from aiming commands such as gh pr create at the upstream, which it otherwise prefers inside a fork.