Git Fetch and Local Knowledge of a Remote

Fetch obtains objects and updates configured remote-tracking references. It can show what changed on a server without integrating those changes into the active branch.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two stored names
  2. Choose integration deliberately
  3. Track where remote knowledge can be stale
  4. Compare explicit refs before deciding how to integrate

Trace two stored names

If the remote moves from A to B, a fetch can update the remote-tracking reference to B while the local work branch still points at A. Branch references help separate those names.

Choose integration deliberately

Inspect the commit ancestry and local edits before merging or rebasing. A fast-forward is possible if the local tip is already an ancestor of the remote tip.[1]

Track where remote knowledge can be stale

Your local branch and local view of origin/main both point to A. A teammate updates the server to B. Until fetching, your local remote-tracking reference can still show A. After a normal fetch of that branch, it shows B while your local checked-out branch can remain at A. See pull and integration.

Before fetch: local main=A, origin/main=A, server main=B
After fetch: local main=A, origin/main=B, server main=B
Integration is a separate step

Compare explicit refs before deciding how to integrate

A fetch of another remote or a restricted refspec may not update the reference you expect. Inspect the configured target and updated pointer. Read incoming changes without requiring a change to the working tree.

References

  1. Scott Chacon and Ben Straub, Pro Git ↩