Practice: Remote Challenges
Push, pull, and status.
Let's practise working with GitHub. The secret to remotes is reading git status carefully. It tells you whether you're ahead, behind, or both. Here are three situations.

- Practise with GitHub
- Read git status carefully
- Ahead, behind, or both
Ahead
Situation one. We committed, but haven't pushed. After a fetch, status says, your branch is ahead of origin main by one commit. Ahead means you have commits GitHub doesn't. The fix is git push.
git fetch git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean git push To https://github.com/sam/my-site.git f63a17a..e8dbc83 main -> main
Behind
Situation two. A teammate pushed, and we haven't. After a fetch, status says we're behind by one commit, and can be fast forwarded. Behind means GitHub has commits we don't. The fix is git pull.
git fetch From https://github.com/sam/my-site f63a17a..7893b97 main -> origin/main git status On branch main Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) nothing to commit, working tree clean git pull Updating f63a17a..7893b97 Fast-forward index.html | 1 + 1 file changed, 1 insertion(+)
Diverged
Situation three. Both of us committed. After a fetch, status says the branches have diverged, with one commit each. Diverged means both sides have something new. The fix is git pull, which merges, then git push.
git fetch From https://github.com/sam/my-site f63a17a..7893b97 main -> origin/main git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean git pull --no-edit Merge made by the 'ort' strategy. index.html | 1 + 1 file changed, 1 insertion(+) git push To https://github.com/sam/my-site.git 7893b97..b3fd521 main -> main
Summary
Ahead means push. Behind means pull. Diverged means pull, then push. Always fetch first, so status is up to date. Next, using GitHub to sync your own two computers.
Key takeaways- Ahead: git push
- Behind: git pull
- Diverged: pull, then push