Cloning in Git
This article belongs to the Git Basics to Advanced course, which is currently being revisited with updated architectural patterns and content. Content may be refined shortly.
1. Cloning a Remote Repository
Cloning copies an existing Git repository from a remote server (like GitHub, GitLab, or Bitbucket) to your local machine.
When you clone, Git does not merely download the latest files. It replicates the entire commit history, all branches, tags, and internal objects, allowing you to work completely offline and push changes back when ready.
git clone https://github.com/arjit-32/highlight-hero.git
2. Interactive Cloning Visualizer
Observe how cloning sets up your local folder, downloads objects, maps remote tracking branches (origin/main), and checks out your local working branch:
Git Clone Under the Hood
Step 1 of 2: Remote Repository on GitHub
$ git ls-remote https://github.com/arjit-32/highlight-hero The remote repository on GitHub contains commit history C1 → C2 → C3 on remote branch origin/main.
3. Cloning Local Repositories
You can also clone repositories already present on your local file system:
# Clone local repo into a new directory
git clone highlight-hero cloned-highlight-hero
4. Useful Cloning Flags
Clone into a Custom Folder
By default, Git creates a directory matching the repository name. You can supply a custom target folder:
git clone https://github.com/arjit-32/highlight-hero.git my-custom-folder
Shallow Clone (--depth 1)
For large repositories with thousands of past commits, fetch only the latest revision to save bandwidth and disk space:
git clone --depth 1 https://github.com/arjit-32/highlight-hero.git
Clone a Specific Branch
To clone only a particular feature or release branch:
git clone -b develop --single-branch https://github.com/arjit-32/highlight-hero.git
5. What Happens During git clone?
- Git creates a directory matching the repository name.
- Initializes an internal
.gitdatabase and adds a remote link namedoriginpointing to the source URL. - Downloads all historical commit objects, trees, and refs.
- Sets up remote-tracking branch pointers (
remotes/origin/*). - Checks out the default branch (e.g.
mainormaster) so you can begin editing immediately.