git fetch
The command that downloads new commits and refs from a remote and updates your remote-tracking branches, without changing your own branches or files.
In more detail
After git fetch, git status can say you are behind, and git log origin/main shows the new commits, but your working tree and local branches are exactly as they were. It is always safe to run.
Example
git fetchRelated terms
- git pull — The command that fetches from the upstream remote and then merges (or, if configured, rebases) the new commits into your current branch.
- remote-tracking branch — A local, read-only record of where a branch on a remote pointed the last time you talked to it, such as origin/main.
- remote — A short name saved in a repository's config that stands for another repository's location, a URL or a path, so you can fetch from and push to it.
Taught in
- What A Remote Actually Is — Advanced Git Internals & Distributed Workflows
- Clone, Forks, Push, And The Upstream Branch — Advanced Git Internals & Distributed Workflows
- Fetch Is Not Pull — Advanced Git Internals & Distributed Workflows
- Amend, And The One Hard Rule — Advanced Git Internals & Distributed Workflows