Git Fetch vs Git Pull

Git Fetch vs Git Pull

I noticed that many people are facing problem with git fetch and git pull . Don?t be confused with these two commands. I am going to explain these two commands.

git fetch gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. But it does not merge them with your current branch. If you type git pull origin <your branch name> you will see the changes but you will notice that it still isn?t merged into your local branches. The interesting thing about git fetch is that it will not affect to your local branch. Commits, tags, files which are updated to the remote branch, it will retrieve that from the remote branch only and make your local repository updated. But it won?t merge.

On the contrary, git pull is the combination of git fetch and git merge . It will fetch from the remote to local and automatically merge them to your current branch. So, now if you type git log you will see the changes and also you will notice that it merged into your local branches. After a git pull operation, your working copy should be fully synchronized, barring any local modifications you have made. So, no need to type git checkout origin <your branch name> .

Here is the workflow of git fetch and git pull

Image for postgit fetch vs git pull

Git fetch vs git pull

Image for postgit fetch vs git pull

Type a command for fetching the changes and merge them into your branches?

If you see this kind question, don?t be hesitate. The command will be git pull origin <your branch name> .

Useful Links

https://www.git-tower.com/learn/git/faq/difference-between-git-fetch-git-pullhttps://www.atlassian.com/git/tutorials/syncing/git-fetchhttps://www.atlassian.com/git/tutorials/syncing/git-pull

Thanks for attention to this blog. I hope you have learned something.

15