Skip to the workspace
Pebellslearn by building
Git Remotes  ›  Lesson

Cloning a Repository

Cloning Repositories 12 mingit clone copies a repository's full history into a new folder, records the source as the remote origin and checks out the default branch.

git github / Cloning a Repository

Explore each scene at your own pace.

01 · The rule

The rule

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 clone copies the whole history and remembers where it came from as origin.

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-box

That one command:

  1. Creates a folder named after the repository, recipe-box.
  2. Downloads every commit and every branch, not just the latest files.
  3. Records the source URL as a remote named origin.
  4. 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-recipes

URLs come in two main forms:

https://github.com/asha-dev/recipe-box.git    # HTTPS
git@github.com:asha-dev/recipe-box.git        # SSH

HTTPS 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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.