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

    Branches and merging · Lesson 6 of 15

    Merge: fast-forward and three-way

    Combine a branch and understand when Git moves a name or creates a merge commit.

    11 minutes2 games

    If main has not moved since feature began, Git can fast-forward by moving main to the same commit. If both sides moved, a three-way merge uses their common ancestor and usually creates a merge commit.

    Choose target branch

    git merge feature

    Fast-forward or three-way

    Test the result

    Git
    git init -q -b main
    echo "base" > app.txt
    git add app.txt
    git commit -q -m "Base"
    git switch -q -c feature
    echo "ready" > feature.txt
    git add feature.txt
    git commit -q -m "Add feature"
    git switch -q main
    git merge -q feature
    git log --format=%s

    Merge into the branch you are on: to bring feature into main, switch to main then git merge feature. After testing, the feature name can be deleted because main still reaches its commits.

    Important

    A successful merge does not prove the program is correct. Git combines text, not business rules; run tests and review the diff.

    Quick question

    Does a fast-forward create a merge commit?

    Interview question

    Merge versus rebase?

    Exercise

    Make Feature ready on feature, merge it into main, then print subjects.

    Expected output:
    Feature ready
    Base
    Git
    git init -q -b main
    echo "base" > app.txt
    git add app.txt
    git commit -q -m "Base"
    git switch -q -c feature
    git log --format=%s

    Learn more from

    • Git: git-mergegit-scm.com
    • Atlassian: Merging vs rebasingatlassian.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousBranches and HEADNextResolve merge conflicts
    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.