Menu
Coddy logo textTech

Git Clone

Last updated

git clone <url> copies a remote repository - all its files, branches, and history - to your machine, and sets up origin pointing back at the remote so you can push and pull. It's how you start working on an existing project, as opposed to git init, which starts a brand-new empty repo.

Try these in the terminal playground - a real shell in your browser, nothing to install.

git clone copies the remote repository - every commit and branch - into a new local repository wired to origin.

Syntax

CommandWhat it does
git clone <url>Clone into a folder named after the repo
git clone <url> myappClone into a folder named myapp
git clone -b dev <url>Clone and check out the dev branch
git clone --depth 1 <url>Shallow clone (latest commit only)
git clone --recurse-submodules <url>Clone the repo and its submodules

HTTPS vs SSH

ProtocolURL form
HTTPShttps://github.com/user/repo.git
SSHgit@github.com:user/repo.git

Git clone FAQ

What does git clone do?
It downloads a full copy of a remote repository - every file, branch, and commit - into a new local folder, and configures the remote as origin. After cloning you can immediately work, commit, and push. Unlike git init, which creates an empty repo, clone brings an existing project with its history.
How do I clone into a specific folder?
Add the folder name after the URL: git clone <url> myfolder clones into myfolder instead of the repo's default name. The folder is created if it doesn't exist.
How do I clone a specific branch?
Use git clone -b <branch> <url> to clone and check out that branch. Add --single-branch to fetch only that branch's history rather than all branches - useful for large repos. See the git clone branch page for more.
What is a shallow clone?
git clone --depth 1 <url> fetches only the most recent commit instead of the entire history, producing a much smaller, faster download. It's ideal for CI or when you only need the latest code. You can later fetch more history with git fetch --unshallow.
Can I practice this online?
Yes. Open the terminal playground to run git clone in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers getting a repository step by step.
Coddy programming languages illustration

Learn Git with Coddy

GET STARTED