This article covers how to use the command 'Git Fetch'.
If another developer has pushed commits to the remote repository, then you need to fetch those changes so that they appear in your local repository.
But wait, isn't this the same as using git pull? Well, not quite:
- Using git fetch will download the latest metadata information from the remote repository and use it to update your local repository. It will provide an up-to-date list of all the changes that have been pushed. It will not however, apply any of those changes to your code.
- Similarly, git pull will fetch the latest changes, but also merge those changes directly.
In fact, git pull is simply a combination of git fetch and git merge.
To perform a fetch, simply run the following:
git fetch <remote-name>
You can also specify a branch name, if you only want to fetch a specific branch:
git fetch <remote-name> <branch-name>
Or, to get all the changes available, use the --all parameter:
git fetch --all
Sometimes it may be useful to see if there are any changes on the remote repository, without fetching them.
To do this, you can use the --dry-run parameter, to see what actions would be applied in a fetch, without applying them:
git fetch --dry-run