Master: git fetch
In this video we'll learn some of the additional options for git fetch
.
In init: git fetch, we covered how to use git fetch
to fetch from a single remote.
If we have multiple remotes, we can use the --all
option to fetch for all remotes.
We can do so by running:
git fetch --all
.
In this case, it will download information from both the origin and upstream remotes.
To fetch from multiple remotes, but not all of them, we can use the --multiple
option.
For example, if I didn't want to fetch from all remotes, but specifically the origin and upstream remote, I could run:
git fetch --multiple origin upstream
The final option we'll learn is --prune
.
Over time, you'll build up a lot references. By default, git fetch
does not remove local references that no longer exist on a remote.
To do so, you have to add the --prune
option.
Let's demonstrate this by pushing a test branch to GitHub.
Then we'll remove the test branch on GitHub.
If I run git fetch origin
, notice nothing is updated.
If I run git log --oneline --decorate --graph --all
, we still see a local reference to origin/test.
However, if we run git fetch --prune origin
, we see from the output it deleted the test branch, and we can verify it no longer appears when running git log
.