Sitemap

GitHub Key points — part 5

1 min readApr 19, 2023

--

Git fetch vs Git pull

The “git fetch” command allows you to download files from a remote repository without modifying your working copy. It downloads and stores the files as a new branch.

Get Lamai Anthony’s stories in your inbox

Join Medium for free to get updates from this writer.

For example, if you want to compare your local “main” branch to the remote “main” branch repository or verify changes made by other developers to the remote branch, you can use the “git fetch” command and then checkout the remote branch.

git fetch remote main

To view the remote branch that was fetched, run the “git branch -r” command. The branch with the remote prefix will be displayed.

origin/main
remote/main

On the other hand, “git pull” downloads the files to your local repository and merges them with your local copy. This is because once “git pull” is run, a merge operation is initiated.

#Fetch all remotes.
git pull - all

#Fetch a limited number of commits.
git pull - depth=<depth>

#Show the action that would be completed without actually making changes to your repo.
git pull - dry-run

#Remove all remote references that no longer exist on the remote.
git pull - prune

#Do not fetch tags
git pull - no-tags

--

--

Lamai Anthony
Lamai Anthony

Written by Lamai Anthony

Technical Engineer passionate about continuous learning and evolution. Always surfing the net and trying projects in search of new ideas and perspectives