Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    GITGit & GitHub

    Basics: from file to commit

    • Why version control?
    • From working tree to commit
    • Read history and differences
    • .gitignore and useful commit messages

    Branches and merging

    • Branches and HEAD
    • Merge: fast-forward and three-way
    • Resolve merge conflicts
    • Park work temporarily with stash

    Undo without losing work

    • Restore and unstage
    • Reset: soft, mixed and hard
    • Revert or reset?
    • Amend and reflog: rescue recent work

    Remotes and GitHub Flow

    • Remotes, push and tracking
    • Fetch, pull and rejected pushes
    • GitHub Flow: complete project
    Git & GitHub

    Remotes and GitHub Flow · Lesson 14 of 15

    Fetch, pull and rejected pushes

    Synchronize team work, inspect before merging, and handle non-fast-forward rejection correctly.

    12 minutes2 games

    fetch downloads remote history and updates origin/* without changing your files. pull is roughly fetch followed by merge (or rebase by configuration). Separating them is calmer: fetch, inspect diff and log, then integrate deliberately.

    Teammate pushes

    fetch updates origin/main

    inspect differences

    merge/rebase then push

    Git
    git init -q -b main
    echo "base" > app.txt
    git add app.txt
    git commit -q -m "Base"
    git remote add origin https://example.com/team/app.git
    git push -q -u origin main
    teammate app.txt "remote update" "Teammate update"
    git fetch origin
    git log --all --format=%s

    If a teammate pushed while you built on an older base, the remote rejects your non-fast-forward push. Do not force automatically. Fetch, pull or merge, resolve conflicts, test, then push. The rejection protects someone else's work.

    Important

    pull can produce a surprise merge when your tree is dirty. Check status first and know your pull.rebase setting. Use --force-with-lease only for intentional rewrites; it checks that the remote has not changed since your last fetch.

    Quick question

    Which command downloads updates without changing the working tree?

    Interview question

    Why was a push rejected as non-fast-forward?

    Exercise

    Push main, let a teammate add remote, pull quietly, and print the file.

    Expected output: remote

    Git
    git init -q -b main
    echo "base" > app.txt
    git add app.txt
    git commit -q -m "Base"
    git remote add origin https://example.com/team.git
    git push -q -u origin main
    cat app.txt

    Learn more from

    • Git: git-fetchgit-scm.com
    • GitHub Docs: Non-fast-forward errordocs.github.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousRemotes, push and trackingNextGitHub Flow: complete project
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.