Data report"State of code review 2024" is now liveRead the full report

The differences between git pull and git clone

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


In the Git version control system, git clone and git pull facilitate the management of repositories. Although both commands are used for obtaining repository data, they serve distinct purposes and operate in different contexts. This guide will compare and contrast these commands, highlighting their uses, processes, and scenarios where each command is appropriate.

Purpose: git clone is used to create a local copy of an existing remote repository, a repository hosted remotely on a service like GitHub or GitLab. This command is typically used when you need to obtain a repository for the first time. It not only downloads the repository's files but also its complete version history.

Usage:

Terminal
git clone <repository-url>

Key features:

  • Full repository copy: Clones everything from the repository, including all branches and tags.
  • Initial setup: Automatically sets up local branches to track remote branches and initializes a new .git directory, which stores all of the metadata and configuration files for the repository.
  • Networking overhead: Generally done once for a repository because it downloads the entire history, which can be network-intensive.

Example: To clone a repository from GitHub:

Terminal
git clone https://github.com/exampleuser/example-repo.git

This command creates a new directory example-repo in the current directory, initializes a .git directory inside it, and pulls down all the data from the repository.

Purpose: git pull is used to fetch and integrate changes from a remote repository into the current branch in your local repository. It's typically used to update your local repository to reflect changes made in the remote repository.

Usage:

Terminal
git pull <remote> <branch>

Running git pull will fetch and merge the latest changes from the corresponding remote branch into your current local branch.

Key features:

  • Update and merge: Fetches changes from the remote repository and immediately attempts to merge them into the branch you are currently working on.
  • Requires existing repository: Can only be used if a local repository already exists and is linked to a remote repository.
  • Efficiency: More network-efficient than git clone because it only downloads new data since the last fetch or pull.

Example: To update your local main branch from the remote origin:

Terminal
git pull origin main

This command fetches the latest changes from the main branch of the origin remote and merges them into your current local main branch.

git clonegit pull
PurposeObtain a full copy of a repository for the first time.Update an existing local copy with changes from remote.
OperationCopies all files, branches, and history.Updates current branch with remote changes.
Network usageHigh, as it downloads the entire repository.Lower, updates only with new changes.
DependenciesNone, can be run to create a new local repo.Requires an existing local repo linked to a remote.
ResultNew local repository with remote tracking branches set up.Updated files in current branch, merge performed.
  • Use git clone when:

    • Starting work on a new project that exists remotely.
    • Needing to obtain a repository with all its branches and history for the first time.
  • Use git pull when:

    • You already have a local copy of the repository and need to synchronize it with changes from the remote repository.
    • Regularly updating local development branches with new commits from collaborators.

For further reading on the two commands, see the official Git documentation on the clone and pull commands.

Git gud
"It's the first Git workflow I've used that actually feels good."
–@robboclancy
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2