Before jumping into difference of Git Fetch and Git Pull, lets understand them. Version control is an integral part of IT development. It is very essential thing in Software development life-cycle which helps you to manage your code repositories for Development and different environments.
Now a days, Most of the projects are using Git as one of the Subversion control tool. While working with Git, As a beginner first question comes to my mind is what’s the different between Git fetch and Git pull. Main purpose for both is to download the latest code/source files from remote repositories.
Whenever you work with Git, Whenever you checkout any branch it is replica/snapshot version of the actual remote code repositories. And it is very important that you need to work on the latest code and you check-in the latest code to avoid wasting your time to merge code manually.
Git Fetch
git fetch origin
git fetch
only downloads the Remote repositories but it doesn’t modify or tries to merge files/code. It’s one of the great ways to get the idea about remote repositories into Local. It is heavily used update your remote-tracking branches underĀ refs/remotes/
.
As git fetch
is not modifying any files in Local repositories, You can be assured that it won’t update/modify or delete any files into your local repositories.
Git Pull
git pull origin
While on other side, git pull
is not only download the latest files/code from remote repository but also it will merge with your local repositories files/code.
git pull
is git fetch
followed by git merge
. i.e. Pull = Fetch + Merge.git pull
is used to bring your local branch version to latest with it’s remote repository and also updates other remote-tracking branches.
Also please note that as git pull is merging code/files, sometimes you may encounter "merge conflicts"
when you try to pull changes from remote branch.
git pull
with clean working copy and if you want to save your changes temporary, You may use "git stash"
your changes and then do a fresh “git pull”.