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 5 of 15

    Branches and HEAD

    A branch is a movable name, and HEAD says where you are.

    10 minutes2 games

    A branch is not a full copy of your files; it is a lightweight name pointing to a commit. Every new commit advances the current branch. HEAD normally points to that branch, telling Git which name should move.

    A: start

    B: login ← main

    C: tests ← feature ← HEAD

    Branches are names on commits; the commits are shared.

    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 "feature" >> app.txt
    git commit -q -am "Build feature"
    git branch -v

    git switch -c feature creates a branch at the current commit and moves HEAD to it. git switch main updates files to match main's snapshot. Commit or stash first if local edits would conflict.

    Important

    A branch name is not a folder and does not reserve a project copy. It is cheap to create or delete; before deletion, ensure no important commit becomes unreachable.

    Quick question

    What moves when you commit on feature?

    Interview question

    What is detached HEAD?

    Exercise

    Start with a commit on main, create and switch to feature, then list branches.

    Expected output:
    * feature
    main
    Git
    git init -q -b main
    echo "base" > app.txt
    git add app.txt
    git commit -q -m "Base"
    git branch

    Learn more from

    • Git Book: Branchesgit-scm.com
    • GitHub Docs: About branchesdocs.github.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    Previous.gitignore and useful commit messagesNextMerge: fast-forward and three-way
    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.