Git Fetch vs Git Pull
Hello git lovers! Since I’ve heard lot of confusions about the two commands git fetch and git pull, I thought to share my knowledge regarding these commands to you all.
Github has done an excellent job in version controlling chores in recent past. It has become the biggest internet hosting service for software development and version control using Git. From this blog, I’m going to talk about functioning of git fetch and git pull commands which is a confusing topic for young tech enthusiasts.
Git Fetch
Git fetch command retrieves all the changes that take place in the remote repository, but it doesn’t compare or merge the changes to the local repository.
Let’s consider the following example
Here, remote repository has a new change and the local repository is yet to get the change.
Let’s see the status after executing the git fetch command
Git Pull
Git pull command is more like a combination of git fetch command and git merge command.
This command retrieves all the changes in the remote repository and it merges the remote repository copy local repository.
If you have multiple branches,
Git pull command retrieves all the changes in the remote repository and it merges the remote repository copy of the active branch (which is the branch you are in while you enter the git pull command) to the corresponding branch in the local repository.
Here, User has entered the git pull command from branch B. Therefore, First it fetch do the fetching part (fetch new change in branch A and new change in branch B). Then it merges the copy of branch B in the remote repository to the branch B in local repository.
That’s a wrap! Hope you got the knowledge about git fetch and git pull commands.