Mirror a remote repo onto your disk, refs and all.
Make a local copy of a remote repository — every commit, every branch's history, the whole object database — and check out a working tree from it. Equivalent to init + remote add origin + fetch + checkout, in one shot.
Clone copies the entire .git/ from the source over the wire (or filesystem), then writes one branch's tree to the working directory. The remote's branches are recorded as remotes/origin/ refs locally; you only have a local* branch for the one you're checked out on. Everything else is one git switch away.
git clone [<options>] <repository> [<directory>]| Flag | What it does |
|---|---|
--branch=<name>, -b | Check out a specific branch (or tag) instead of the default. |
--depth=<n> | Shallow clone — only the last n commits per branch. Faster, smaller. Limits history operations. |
--single-branch | Fetch only the branch you're checking out. Combine with --depth for tiny clones. |
--filter=blob:none | Partial clone: skip blobs at clone time, fetch on demand. Good for huge repos. |
--bare | Clone as bare — no working tree. |
--mirror | Like --bare but also mirrors all refs 1:1, including notes and remote-tracking refs. For backup mirrors. |
--recurse-submodules | Initialize and clone submodules too. |
--origin <name>, -o | Name the remote something other than origin. |
--no-checkout, -n | Don't pull files into the working tree. Cheap setup before sparse-checkout. |
--mirror).--depth=1 for fast pipeline runs.--filter=blob:none --sparse).$ git clone git@github.com:user/proj.git
$ cd proj$ git clone --depth=1 https://example.com/repo.git build/$ git clone --filter=blob:none https://example.com/big-repo.git$ git clone --mirror git@host:repos/proj.git proj.git
# Later: cd proj.git && git remote update--depth and --filter look like wins until you need to rebase against an old commit and Git has to round-trip to fetch it.git@host:path) when you have keys set up. HTTPS is fine for read-only public repos.git sparse-checkout before you clone — combine --no-checkout + --filter=blob:none + sparse-checkout init.--depth clones can't push their full history. They can push new commits, but rebasing onto something deeper than the depth requires fetching more.--mirror clones are bare and refuse to pull from one remote and push to another the way a normal clone might. Know what you're getting.git clone and immediately git pull, you've done a redundant fetch. The clone already brought everything.Hit each option, then Check answers. Score is recorded; Next is always open.