Git Fetch (original) (raw)

Last Updated : 27 Dec, 2025

git fetch is a safe and non-disruptive Git command that checks for and downloads the latest updates from a remote repository without merging them into your local branch, giving developers full control over when and how changes are integrated.

Working of Git Fetch

git fetch works by safely retrieving the latest updates from a remote repository without altering the local working branch.

When to Use Git Fetch

Here are some cases where git fetch is particularly useful:

Syntax

git fetch

**Example:

git fetch origin

Fetches updates for all branches from the remote repository named origin.

**Example:

git fetch origin feature-branch

Fetches only the updates from the feature-branch on the remote repository.

**Example:

git fetch origin dev

Fetches the latest changes from the remote dev branch for review.

**Example:

git log origin/dev

Displays the commit history of the fetched remote dev branch.

**Example:

git fetch --all --tags

Fetches all branches and tags from all configured remote repositories.

Difference Between Git Fetch and Git Pull

Here's the difference between Git Fetch and Git Pull:

Git Fetch Git Pull
Checks for updates from remote without applying them Fetches and merges changes into your current branch
Safe for reviewing before merging May introduce merge conflicts immediately
Keeps local working directory unchanged Alters working directory based on remote updates
Best for cautious syncing Best when you're ready to integrate updates

Advanced Usage of Git Fetch

1. Fetching and Pruning Deleted Branches

Over time, remote branches may be deleted. You can clean up stale branches with:

git fetch --prune

This command removes references to branches that no longer exist on the remote repository.

2. Fetching Specific Tags

If you want to fetch a particular tag, use:

git fetch origin tag v1.0.0

3. Shallow Fetching

In cases where bandwidth or storage is limited, you can perform a shallow fetch:

git fetch --depth=1

This fetches only the latest commit, reducing the amount of data downloaded.

Best Practices