Remotes and GitHub
Fetch and pull changes
Choose whether to inspect remote work first or download and integrate it immediately.
git fetch downloads objects and updates remote-tracking references. It does not change your current branch, index, or working files. I fetch first when I want to see what landed on the remote before I merge anything.
In notes-project, run:
git fetch origin
git status
After a teammate pushed to main, git status might say:
Your branch is behind 'origin/main' by 2 commits.
Your checked-out files did not change yet. Only origin/main moved.
Inspect commits the remote branch has that yours does not:
git log --oneline HEAD..origin/main
You might see:
fedcba9 Add search page
9876543 Fix README typo
Review that list before integrating anything.
git pull performs a fetch, then merges (or rebases) into your current branch. If you only want a pull that can fast-forward:
git pull --ff-only
When your local main diverged, Git stops:
fatal: Not possible to fast-forward, aborting.
Fetch, inspect the graph with git log --oneline --graph --all, then merge or rebase deliberately. Do not --ff-only your way past a real divergence.
Another failure: you edited notes.txt locally while origin/main moved. git pull without --ff-only may merge and create a merge commit you did not expect. Fetch first, read git log HEAD..origin/main, then choose merge or rebase on purpose.
After a successful fast-forward pull, git log --oneline -3 should include the commits you saw in the fetch range. HEAD and origin/main point at the same commit.
git pull --rebase is another integration style. It replays your local commits on top of origin/main. Know your team’s preference before you use it on notes-project.
Before pulling, check git status. Uncommitted edits to notes.txt can conflict with incoming changes. Commit them, stash them, or switch branches. Do not discard them just to make the command pass.
Fetch first when you want to inspect. Pull when you are ready to integrate.
Try this: fetch notes-project when origin/main is ahead, compare HEAD with origin/main, then predict whether git pull --ff-only can succeed.
Lesson completed