Remotes and GitHub

Fetch and pull changes

Choose whether to inspect remote work first or download and integrate it immediately.

8 minute lesson

~~~

git fetch downloads objects and updates remote-tracking references without changing your current branch, index, or working files.

Run:

git fetch origin
git status

Now inspect commits that the remote branch has and your branch does not:

git log --oneline HEAD..origin/main

You can review the incoming work before integrating it.

git pull performs a fetch, then integrates the selected remote branch into your current branch. The integration can merge, rebase, or require an explicit choice, depending on the command options and configuration.

If you only want a pull that can fast-forward, say so:

git pull --ff-only

Git stops instead of creating a merge commit when the histories diverged.

Before pulling, check git status. Local uncommitted work can conflict with files the integration needs to update. Preserve that work deliberately instead of discarding it to make the command pass.

Fetch first when you want to inspect the incoming work before combining it.

Exercise: fetch a repository with an updated remote branch. Compare HEAD with origin/main, then predict whether git pull --ff-only can succeed.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →