Tutorials  /  Linux Basics

Git Fetch Explained: Update Remotes Safely and Cleanly

Ccentron Redaktion · November 2025 ·5 min read ·Linux Basics, Tutorial

The git fetch command allows you to view updates from a remote repository without changing your local branches. It updates the remote-tracking branches and saves the information in FETCH_HEAD. After fetching, you can decide to merge or rebase those updates into your local repository.

This guide explains how to use git fetch to pull updates from remote repositories — including specific branches, all remotes, and cleanup tasks for deleted branches.

The Short Answer Version

If you already know Git and just need quick reference commands for fetching updates:

Console
# Fetch updates from a specific remote
$ git fetch <remote>

# Fetch updates of a specific branch from a remote
$ git fetch <remote> <branch>

# Fetch updates from all remotes
$ git fetch --all

# Remove local references to deleted remote branches
$ git fetch --prune
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Common Options for git fetch

Here are some frequently used flags for retrieving updates from remotes and managing remote-tracking branches:

Flag Description
--all Fetches updates from all remotes, not just the default one (e.g., origin).
--prune Removes local references to branches deleted on the remote.
--dry-run Shows available updates without applying them.
--verbose Displays detailed information during the operation.
--tags Fetches all tags along with branches.
--force Forces updates to match the remote, even if it overwrites local references.
--multiple Fetches from multiple remotes in one command.
--atomic Ensures all references update together or none at all to prevent partial updates.

Fetch All Remote Updates

Use git fetch to download the latest commits and branches from a remote repository. This operation updates your remote-tracking branches without merging them into your local ones, allowing you to review changes before applying them.

Command Syntax

git fetch <remote>

Here, <remote> refers to the repository you want to fetch from (for example, origin).

Command Demonstration

First, make a change in your remote repository — such as editing a file or creating a new commit. Then, check your configured remotes locally:

Console
$ git remote -v

This lists all remotes with their associated URLs.

Example Output

Code
origin  https://github.com/username/test-repo.git (fetch)
origin  https://github.com/username/test-repo.git (push)

Now, fetch the latest updates from the remote repository:

Console
$ git fetch origin

This retrieves updates from all branches in origin and updates their remote-tracking branches.

Inspect the Fetched Changes

Console
$ git log origin/main

The git log command shows the commit history of the branch.

Sample Output

Code
commit 8ecb58dbecee84f9fd0b2e0089df7dae63814be4 (origin/main, origin/HEAD)
Author: username <username@gmail.com>
Date: Sun Sep 7 22:14:54 2025 +0530

    New Line Added

Merge the Fetched Changes

Console
$ git merge origin/main -m "commit message"

The git merge command merges fetched changes into your local branch.

Fetch a Specific Remote Branch

To retrieve updates from a specific branch, include the branch name in your fetch command. This lets you fetch changes for a particular feature or topic branch without updating all branches.

Command Syntax

git fetch <remote> <branch>

Command Demonstration

After committing changes to a specific remote branch, fetch it locally:

Console
$ git fetch origin feature-login

This fetches only the updates from the feature-login branch and updates origin/feature-login.

Review the Fetched Branch

Console
$ git log origin/feature-login

This shows the commit history of the fetched branch.

Merge the Remote Branch into Your Local Branch

Console
$ git merge origin/feature-login -m "commit message"

This merges the updates from the remote feature-login branch into your current branch.

Fetch from All Remotes

If your project uses multiple remotes, add the --all flag to fetch updates from each one simultaneously. This ensures all remote-tracking branches stay up to date.

Console
$ git fetch --all

This downloads changes from every configured remote. You can also include --verbose for detailed output.

Clean Up Deleted Remote Branches

When branches are deleted from the remote repository, run git fetch --prune to remove outdated references and keep your branch list clean.

Console
$ git fetch --prune

This removes references to deleted remote branches without altering your local branches.

Conclusion

This article covered how to use git fetch to view updates from remote repositories, fetch specific branches, update all remotes, and clean up outdated branch references. Using these commands keeps your local work synced and organized while avoiding unintentional changes to your local branches. For advanced configurations, refer to the official Git documentation.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren