git fetch <remote>
This command updates your local view of a specific remote repository so you can see new commits, branches, and tags without modifying your working directory or current branch.
It connects to the given <remote> (commonly origin or another remote name), reads what has changed on the server, and updates your local remote-tracking branches (like origin/main) and tags to match, but does not merge, rebase, or check out anything automatically in your current branch, which makes it a safe way to sync metadata before deciding how to integrate changes. The remote name after git fetch tells Git which configured remote to talk to, and omitting it (using just git fetch) will fetch from the default remote, usually origin; using flags like --all will fetch from every configured remote, and --prune will remove any remote-tracking branches that were deleted on the server, while -p is just a shorter way to write the same option. You can further refine what is fetched by specifying a branch refspec, for example git fetch origin main, which fetches only the main branch from the origin remote, or by using --tags to fetch all tags explicitly if they are not fetched by default in your setup.
This command is typically followed by inspection or integration commands such as git log origin/main..main to see what changed on the remote before merging, git merge origin/main to integrate the remote tracking branch into your current branch, or git rebase origin/main to replay your local commits on top of the updated remote state. Closely related commands include git pull, which effectively combines this command followed by an automatic merge or rebase (depending on configuration), and git remote -v, which lets you list and verify the available remotes you can use as <remote> values.
Examples:
git fetch origingit fetch upstreamgit fetch origin --prunegit fetch origin main