Skip to content
Foxipa

Suggest an edit

Tell us what should be corrected, clarified, or improved. Submission will be connected to Foxipa’s contribution service later.

No information is sent anywhere yet. Your suggestion is only prepared in your browser.

Learning

Git Pull: Fetching and Integrating Remote History

Understand git pull as fetch followed by integration, including explicit sources, fast-forward updates, divergent histories, merge and rebase modes, and the boundary between fetching and publishing.

Levels: Intermediate ~40 min read

Intermediate

Pull is fetch followed by integration

`git pull` is a compound operation. Git first fetches from the selected remote, then integrates the selected remote branch or ref into the current branch. The fetch can update remote-tracking refs and FETCH_HEAD before the integration changes the current branch.

bash
git pull <remote> <refspec>
git fetch <remote>
git merge FETCH_HEAD

Quick check

Which state transition is distinctive to `git pull` compared with `git fetch`?

The remote has a commit that the current branch does not have.`git pull` can fetch that commit and then update the current branch.

Choose the source explicitly when the workflow requires it

A pull can name a remote and a refspec explicitly, such as `git pull origin main`. The named ref is fetched and then integrated into the current branch. With no explicit source, Git can use the current branch's configured upstream; upstream configuration is taught separately in V446.

bash
git pull origin main
git rev-parse HEAD
git rev-parse refs/remotes/origin/main

Quick check

What does `git pull origin main` identify explicitly?

origin contains a main branch with a newer commit.`git pull origin main` fetches and integrates that selected remote branch into the current branch.

Fast-forward integration moves the current branch without creating a merge commit

When the current branch is strictly behind the selected remote history, a fast-forward can move the current branch tip directly to the fetched commit. No merge commit is needed. This changes the current branch and therefore HEAD when HEAD is attached to that branch.

bash
git pull --ff-only origin main
git log --oneline --decorate -3

Quick check

What happens in a fast-forward pull?

The remote tip descends directly from the current local tip.`git pull --ff-only` can move the current branch directly to that tip.

Divergence requires an integration policy

If the current branch and the selected remote branch have both advanced independently, they have diverged. Git needs an integration policy. `--ff-only` refuses this case; `--no-rebase` asks Git to merge; `--rebase` asks Git to rebase the local work. Rebase mechanics belong to the later rebase curriculum, so this lesson treats `--rebase` as a pull integration mode rather than teaching rebase itself.

bash
git pull --ff-only origin main
git pull --no-rebase origin main
git pull --rebase origin main

Quick check

Which pull option refuses a divergent local and remote history?

The local and fetched remote histories have diverged.`git pull --ff-only` fails rather than choosing a merge or rebase.

Merge and rebase are different integration outcomes

`git pull --no-rebase` uses merge integration. If the histories have diverged and the merge is clean, the result can be a merge commit with the current branch tip as one parent and the fetched history as another. `git pull --rebase` instead rebases local commits onto the fetched upstream history and therefore can rewrite local commit IDs. The rebase algorithm itself is deferred to Phase 7.

bash
git pull --no-rebase origin main
# or, as an explicit equivalent boundary:
git fetch origin
git merge origin/main

Quick check

Which statement correctly distinguishes `--no-rebase` from `--rebase`?

Local and remote histories have diverged.`--no-rebase` can create a merge commit; `--rebase` rewrites the local commits onto the fetched history.

Pull conflicts belong to the integration operation

A pull can enter a merge or rebase conflict state because the fetch succeeds but the selected integration cannot complete automatically. At that point the repository is in the state owned by the underlying merge or rebase operation. Merge conflict resolution and continuation were taught in Phase 5; detailed rebase conflict workflows are deferred to Phase 7.

bash
git pull --no-rebase origin main
git status
# resolve the merge, then use the merge continuation workflow when required

Quick check

If the fetch succeeds but the merge performed by pull conflicts, what is the important boundary?

The fetched history cannot be merged automatically.Inspect the in-progress merge state and use the merge-resolution workflow.

Inspect what pull changed

Because pull combines two state transitions, verify both halves. Compare the current branch tip before and after the operation, inspect the remote-tracking ref and FETCH_HEAD when needed, and inspect history to determine whether the result was a fast-forward, merge, or rebase. A pull is not merely a synonym for fetch.

bash
git rev-parse HEAD
git rev-parse refs/remotes/origin/main
git show --no-patch --format=fuller HEAD
git log --oneline --decorate --graph -5

Pull does not mean push

`git pull` reads from another repository and integrates the selected history into the current branch. It does not publish the current branch back to that repository. Publishing is owned by `git push` in V445. Similarly, remote setup is V442, fetching without integration is V443, and upstream configuration is V446.

Practice what you learned

Use the dedicated Git code-completion exercise for this lesson.

Was this page helpful?

Mark this learning resource complete to track your learning progress.