basics
git clone
Downloads a repository from a remote URL into a new local directory, setting up the remote 'origin' automatically. Includes all commits, branches, and tags by default.
git clone <repository> [<directory>] Common flags
| Flag | Purpose |
|---|---|
| --depth <n> | Create a shallow clone with truncated history |
| --branch <name> | Clone a specific branch instead of the default |
| --recurse-submodules | Initialize and clone submodules recursively |
| --bare | Create a bare repository without a working tree |
| --single-branch | Fetch history for only one branch |
| --filter=blob:none | Partial clone that skips file contents until needed |
Examples
git clone https://github.com/user/repo.git Standard clone into ./repo
git clone --depth 1 https://github.com/user/repo.git Shallow clone with only the latest commit
git clone --branch dev --single-branch [email protected]:user/repo.git Clone only the dev branch via SSH
Gotcha
Shallow clones (--depth) cannot push to some servers and limit history operations like blame or log; convert with 'git fetch --unshallow' when needed.
Related commands
git init
Creates a new empty Git repository by initializing the .git metadata directory in the current or specified folder. Turns any directory into a version-controlled project.
git remote
Manages the set of named remote repositories your local repo tracks, such as origin or upstream. Lets you add, rename, remove, or inspect remote URLs.
git fetch
Downloads objects and refs from a remote without modifying your working tree or current branch. Safest way to see what's new upstream before integrating.
git add
Stages file changes into the index so they are included in the next commit. Supports whole files, directories, and interactive patch selection.
git commit
Records the staged snapshot to the repository history along with a message and author metadata. Every commit is identified by a unique SHA hash.