git clone
git clone
: clone a remote repository into a new directory.
The git clone
command is used to create a local copy of a remote Git repository. It creates a new directory, initializes a Git repository inside it, and copies all the content from the remote source repository. This command also sets up remote-tracking branches for each branch in the cloned repository and creates and checks out an initial branch based on the currently active branch of the remote repository.
When you clone a repository, Git automatically establishes a connection to the original remote repository, which allows you to easily synchronize your local copy with any updates made to the remote. This remote connection is typically labeled as origin
.
git clone
is essential when you want to contribute to existing remote projects, collaborate with others on GitHub, GitLab, or other Git hosting services, or simply create a local backup of a remote repository. After cloning, you have full access to the entire project history and all its branches, and you can work independently without affecting the remote repository until you decide to push your changes.
While git clone
is primarily used with remote repositories, it can technically be used to clone local repositories as well. For example:
git clone /path/to/local/repository new-copy
However, this use case is rarely needed in practice. If you just want to make a copy of a local repository, you're usually better off creating a new repository and copying the files, or using tools like git worktree
if you need to work in multiple directories within the same repository.
Examples
Clone a repository from GitHub to your local machine:
git clone https://github.com/username/repository.git
Clone a repository into a specific directory:
git clone https://github.com/username/repository.git my-project
Clone a repository with a specific branch and without downloading the full history (shallow clone):
git clone --branch develop --depth 1 https://github.com/username/repository.git
Clone a repository with all submodules:
git clone --recursive https://github.com/username/repository.git
Hi! I'm Alex, creator of GitByBit.
And this is Gitopedia—a reference that summarizes knowledge in my Git course.
Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:
Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.