Command Reference

git clone Tutorial

Explains how git clone copies a repository, what origin means by default, and what local branch setup usually looks like after cloning.

Who This Is For
  • Developers who already know basic commit and branch actions
  • Readers who want to understand command boundaries and risk
Prerequisites
  • A basic mental model of worktree, index, and commits
  • Comfort reading `git status` and a small commit graph
Common Risks
  • Using local cleanup commands on already shared history
  • Continuing to rewrite before confirming a recovery path

The short version

git clone copies an existing repository locally, including its history, objects, refs, and default remote configuration.

Basic usage

git clone https://example.com/repo.git
git clone https://example.com/repo.git my-project

What clone sets up

  • a full local repository
  • a default remote usually named origin
  • an initial checkout of the default branch

What problem this command solves in a workflow

git clone copies a remote repository entirely to your local machine, including all history, objects, refs, and remote configuration, then checks out the default branch. Think of it as "how do I get a fully functional, complete repository from scratch to start developing?"

Typical use cases

  • When joining a new project or starting fresh, use git clone to obtain the complete repository history and collaboration capability.
  • Use the cloned repository as your daily development starting point, synchronizing with the remote via fetch and push afterward.
  • In scenarios that need full repository context (like git bisect or git log), cloning is more suitable than downloading a ZIP snapshot.

Diagram view

Clone operation surfaceThe clone command copies the entire remote repository to local, including history, remote config, and initial checkout — the starting point for collaborative development.
Input
Remote repository URLOptional local directory name
Output
Complete local repositoryRemote origin configuredChecked-out default branch
clone is not just downloading files — it gives you a full Git repository and the ability to collaborate.

Special cases and boundaries

  • After cloning, local branches only track the currently checked-out remote branch; other remote branches must be explicitly checked out with git checkout -b or git switch.
  • If you only need the current snapshot without full history, consider downloading a ZIP or using git clone --depth 1 to save time.
  • Clone includes full remote configuration (origin), so you can immediately use git fetch, git pull, and git push to interact with the remote.
  • For large repositories, consider options like --single-branch, --depth, or --filter to reduce the transfer volume.