Git clone
The `git clone` command creates a local copy of an existing Git repository. Unlike downloading a ZIP of the project, a standard clone lets you browse its commit history and work with Git offline.
Also known as: git clone, клонирование репозитория
What cloning gives you
Use git clone when you want to start working on a repository that already exists, such as a team project you need on a new laptop. The source can be a server or another repository on your machine. After cloning, you can inspect old commits, create branches, and commit changes without a network connection. Those commits stay local until you push them to a repository you have permission to write to.
What happens during a standard clone
Git sets up a project directory with a .git directory for repository data and configuration. It copies the history reachable from the branches it fetches and saves the source address as a remote named origin. It records the fetched branch tips under names such as origin/main and origin/develop. These remote-tracking branches reflect what your copy of Git last learned about the source, not what is on the server this second.
Git normally creates one local branch based on the source's default branch and checks out its files into the working tree. It does not create a separate local branch for every branch at the source. That's why git branch can show just main even when git branch -r lists several branches.
Example
git clone https://git.example.com/team/notes.git notes-app
cd notes-app
git status
git branch -a
The second argument names the destination directory. Without notes-app, Git would name it notes. If the destination already exists, it must be empty. git status tells you which local branch you are on, and git branch -a shows both local and remote-tracking branches. A private repository requires read access; cloning it successfully does not tell you whether you can push to it.
When a standard clone isn't the right fit
A CI job that only needs the current code to run tests may use --depth 1 to save download time. This creates a shallow clone: older commits are missing locally, so commands that rely on history may give incomplete results. For example, a build script that derives a version from an older tag may not find it. If the project uses Git submodules, add --recurse-submodules to initialize and fetch them during the clone rather than discovering missing files at build time.
How it comes up in interviews
A common question is what to run when your teammate has pushed a change. If you already have a clone, you don't need another one: git fetch brings in new data and updates remote-tracking branches without changing your current local branch. git pull also attempts to integrate the fetched changes into that branch. Another useful distinction is cloning versus forking: a fork typically creates a separate repository under your account on a hosting service, while cloning makes a local copy. In an open-source workflow, you often fork first and then clone your fork.