Git fetch is used to fetch the updated versions of branches to merge it back on to your local repository’s master branch. It takes the new commits found in the
origin/master branch and downloads it on to your device. Then, you can choose what merging strategy you’d like to merge it onto your local repository’s master branch. The commit’s found on any branch you are working on won’t be affected whatsoever.
You don’t have to use this command if you work alone since
git fetch is only used to fetch the new commits from the
origin/master branch. Because you work alone, the
origin/master branch will remain untouched. Therefore, there is no need to fetch commits from the remote repository since the remote repository will always equal to your local repository. However, if you are using multiple devices, then you have to fetch the
origin/master branch everytime you login to another device.
Git fetch is commonly used in teamworks. Although not all software teams use them, it is a powerful tool used to sync everyone’s local repository. If you don’t fetch the updated versions of the
origin/master branch, then you are risking your team project’s commit history. This will sometimes result in the deletion of your team member’s commits if you don’t fetch their works and merge them properly onto your local repository.
There’s one Git command that can do two Git commands at once. It’s called
git pull. It fetches the
origin/master branch and automatically merges it to your local repository’s master branch. However, I highly encourage you to not use this command. It is best to do things step-by-step to guarantee that there is no mess in the process of fetching and merging branches together.