Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between 'git pull' and 'git fetch'?

What are the differences between git pull and git fetch?

like image 773
pupeno Avatar asked Nov 15 '08 09:11

pupeno


People also ask

What is the difference between git fetch and git pull Mcq?

Git fetch fetches the required information only to the local repository. Git pull fetches the required information not only to the local repository but also to the workspace that you are currently working in.

Is fetch the same as pull?

When comparing Git pull vs fetch, Git fetch is a safer alternative because it pulls in all the commits from your remote but doesn't make any changes to your local files. On the other hand, Git pull is faster as you're performing multiple actions in one – a better bang for your buck.

Is git pull the same as fetch and merge?

The git pull command first runs git fetch which downloads content from the specified remote repository. Then a git merge is executed to merge the remote content refs and heads into a new local merge commit.

What is a git fetch?

Git fetch summary In review, git fetch is a primary command used to download contents from a remote repository. git fetch is used in conjunction with git remote , git branch , git checkout , and git reset to update a local repository to the state of a remote.


2 Answers

In the simplest terms, git pull does a git fetch followed by a git merge.

You can do a git fetch at any time to update your remote-tracking branches under refs/remotes/<remote>/. This operation never changes any of your own local branches under refs/heads, and is safe to do without changing your working copy. I have even heard of people running git fetch periodically in a cron job in the background (although I wouldn't recommend doing this).

A git pull is what you would do to bring a local branch up-to-date with its remote version, while also updating your other remote-tracking branches.

From the Git documentation for git pull:

In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

like image 62
Greg Hewgill Avatar answered Oct 05 '22 03:10

Greg Hewgill


  • When you use pull, Git tries to automatically merge. It is context sensitive, so Git will merge any pulled commits into the branch you are currently working on. pull automatically merges the commits without letting you review them first. If you don’t carefully manage your branches, you may run into frequent conflicts.

  • When you fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your current branch, you must use merge afterwards.

like image 25
Mouna Cheikhna Avatar answered Oct 05 '22 01:10

Mouna Cheikhna