What is the difference between pull and clone in git?

22.9K    Asked by AnkitChauhan in Devops , Asked on Jun 3, 2021

What is the difference between doing (after mkdir repo and cd repo):

git init
git remote add origin git://github.com/chandra/repo.git
git fetch --all
git pull origin master

and

git clone git://github.com/chandra/repo.git

I mean, obviously one is shorter but other than that are they basically doing the same thing?

Answered by Celina Lagunas

git clone vs pull

What is git clone

git clone is how you get a local copy of an existing repository to work on. git pull (or git fetch + git merge ) is how you update that local copy with new commits from the remote repository.

git clone is used for just downloading exactly what is currently working on the remote server repository and saving it in your machine's folder where that project is placed. Mostly it is used only when we are going to upload the project for the first time. After that pull is the better option.

What is git pull?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration workflows.

git pull is a (clone(download) + merge) operation and mostly used when you are working as teamwork. In other words, when you want the recent changes in that project, you can pull.

The clone will setup additional remote-tracking branches.



Your Answer

Answer (1)

In Git, "pull" and "clone" are both commands used for fetching remote repositories, but they serve different purposes:


1. Clone:

When you clone a repository, you create a local copy of an entire repository, including all branches and commit history. It essentially copies the entire repository from a remote location (like GitHub, GitLab, etc.) to your local machine.

Syntax: git clone 2. Pull:

Pull, on the other hand, is used to update your local repository with changes from the remote repository. It fetches the changes from the remote repository and merges them into your current branch.

It's typically used when you want to bring your local copy up-to-date with the latest changes made by others in the remote repository.

Syntax: git pull

In summary, "clone" is used to create a local copy of a repository, while "pull" is used to update your local repository with changes from a remote repository.


6 Months

Interviews

Parent Categories