The 'git fetch' Command

Learn how to use the "git fetch" command.

Fetching from remote

First, you will look at fetching from the remote.

The command git fetch gets the latest changes from the remote repository and copies them into the local repository, updating the local copies of any branches that have been changed.

Crucially, these changes are not mixed with your local branches but are kept in a separate place. So if you have a master branch on the remote Git repository and a master branch on your local Git repository, then your local one will not be affected.

First, make a change to the origin’s repository:

1	cd ..
2	cd git_origin
3	echo 'fetchable change' >> file1
4	git commit -am fetchable

Get hands-on with 1200+ tech skills courses.