Git & GitHub Interview Question #146

What does git fetch --prune do?

Security, Team Workflows, Troubleshooting & Senior Git/GitHub Scenarios Senior Advanced

Quick Interview Answer

git fetch --prune fetches updates and removes stale remote-tracking references for branches that no longer exist on the remote. It does not normally delete your local branches.

Detailed Explanation

git fetch --prune fetches updates and removes stale remote-tracking references for branches that no longer exist on the remote. It does not normally delete your local branches.

Pruning keeps local remote-tracking information accurate, which is helpful after teammates delete merged remote branches.

Code Example

git fetch --prune origin

# View remote-tracking branches
git branch -r

# Equivalent configuration can also be enabled
# according to team preference.