Git Fetch and Prune Overview | Generated by AI

Home 2025.10

What is git fetch?

git fetch downloads the latest changes (commits, branches, tags) from a remote repository without merging them into your current branch. It updates your local remote-tracking branches (e.g., origin/main) to match the remote state. This keeps your local repo in sync but doesn’t alter your working files or local branches.

What is the --prune Option?

The --prune flag tells Git to remove remote-tracking branches that no longer exist on the remote. For example, if someone deletes a branch on GitHub, your local copy (e.g., origin/old-branch) persists unless pruned.

How Does git fetch --prune Work?

Practical Example

Suppose you have:

Running git fetch --prune for origin:

What It Means

It means “fetch the latest remote data and clean up outdated references” in your local repository. Use it regularly to avoid confusion from old branch refs. Equivalent to git fetch followed by git remote prune origin, but conveniently combined. For safety, it only affects remote-tracking branches, not your own work.


Back

x-ai/grok-code-fast-1

Donate