linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Remote repositories/clone

kb/remote ── Remote repositories ── beginner

git clone

Creates a local copy of a remote repository. Under the hood: `init` + add origin + `fetch` the full history + `checkout` the default branch. The first command you run on any project you did not create yourself.

view as markdownaka: git-clone

git clone <url> [dir] does four things in one shot:

  1. git init in the target directory (defaults to the repo name).
  2. Adds a remote named origin with the clone URL.
  3. git fetch origin downloads all objects and refs.
  4. Checks out the default branch (usually main, sometimes master).

After that you have a full working repository: git log, git status, git switch. The entire project history is there, transparent to you.

URL formats

bash
git clone https://github.com/foo/bar.git           # HTTPS
git clone git@github.com:foo/bar.git               # SSH
git clone ssh://user@host/path/to/repo.git         # SSH with port
git clone /path/to/local/repo                       # local

HTTPS requires a login or token on push (or a credential helper to cache it). SSH requires ssh-keys-git but never prompts for a password after setup. Many teams use SSH for exactly that reason.

Useful flags

bash
git clone --depth 1 <url>          # shallow: last commit only
git clone --branch dev <url>       # check out branch dev instead of main
git clone --filter=blob:none <url> # partial: skip blob objects until checkout
git clone --bare <url>             # no working tree, just .git
git clone --recursive <url>        # include submodules (see chapter 13)

--depth 1 saves bandwidth and disk space on large repositories. The cost: you lose old history (git log goes back only to the shallow boundary). Modern Git allows pushing from a shallow clone, but operations that depend on the full history (merging old branches, bisecting far back) will stumble. Suitable for CI where you only need the current state.

What does not clone

  • The .git/config of the source (a fresh one is created on the clone).
  • Local branches in the source that were never pushed to that URL.
  • Hooks from .git/hooks/ (they are local to each clone).
  • The stash of the source.

What does clone: all commits, all branches, all tags (by default), the full history.

Pitfalls

  • Cloning over HTTPS without a credential helper will ask for a password on every push. Fix: git config --global credential.helper (macOS: osxkeychain, Linux: cache, Windows: manager-core).
  • The default remote name is origin. You can set a different one immediately with git clone -o upstream <url>, or rename it later: git remote rename origin upstream.
  • git clone fetches the entire history, which can be gigabytes. For very large repositories, look at --filter=blob:none (partial clone) or --depth (shallow clone).

§ команды

bash
git clone <url>

Full clone from the default branch

bash
git clone --depth 1 <url>

Shallow clone: last commit only, saves bandwidth

bash
git clone --branch dev <url>

Check out branch dev immediately

bash
git clone --recursive <url>

Clone including submodules

§ см. также

  • fetchgit fetchDownloads updates from a remote but **does not touch** your local branches. Updates only refs/remotes/origin/. A safe command: after fetch you can see what arrived and decide what to do with it.
  • remote-cmdgit remoteManages the list of URLs your repository is connected to. After `clone` there is one remote named `origin` by default. You can add a second one (`upstream` for fork flow), remove remotes, or rename them.
  • upstream-vs-originupstream vs originTwo conventional remote names. `origin` is where you cloned from (usually your fork). `upstream` is the "real" project you forked. This is just a convention: nothing is magic, both names can be renamed.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies