Cloning a Repository
Asha has put recipe-box on GitHub, and her brother Ravi wants to add his dal recipe. He does not need a zip file or a shared drive. One command gives him the whole project, with its complete history, ready to work in.
The rule
git clonecopies the whole history and remembers where it came from asorigin.
Every repository on a hosting service has a URL. Ravi passes it to git clone:
git clone https://github.com/asha-dev/recipe-box.git
cd recipe-boxThat one command:
- Creates a folder named after the repository,
recipe-box. - Downloads every commit and every branch, not just the latest files.
- Records the source URL as a remote named
origin. - Checks out the default branch, usually
main, and links it to the remote's copy,origin/main, so later pushes and pulls know where to go.
Want a different folder name? Add it at the end:
git clone https://github.com/asha-dev/recipe-box.git family-recipesURLs come in two main forms:
https://github.com/asha-dev/recipe-box.git # HTTPS
git@github.com:asha-dev/recipe-box.git # SSHHTTPS works anywhere and asks you to sign in when you push (GitHub expects a token or a credential helper, not your account password). SSH uses a key pair you set up once, after which pushes need no typing. Either gives you the same repository.
Cloning and git init are the two ways a repository begins on your machine. git init starts a new, empty history; git clone starts from an existing one. Never run git init inside a folder you just cloned: it already is a repository.