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

    Basics: from file to commit · Lesson 2 of 15

    From working tree to commit

    Understand the three areas and use status, add and commit confidently.

    11 minutes2 games

    Git separates work into three areas. The working tree holds files you edit. The staging area is the exact proposal for the next commit. The repository stores snapshots. You can edit five files but create a focused commit from only two.

    Working tree

    git add

    Staging area

    git commit

    Repository

    Git
    git init -q -b main
    echo "v1" > app.txt
    git status -s
    git add app.txt
    git status -s
    git commit -q -m "Add app file"
    git log --format=%s

    In status -s, the first column describes staging and the second the working tree. ?? is untracked, A is staged, and M is modified but unstaged. A commit is a snapshot, not a file-save operation.

    Important

    git add . may include debug files or secrets. Review git status and git diff --staged before every commit, and keep each commit focused on one idea.

    What's the output?

    git init -q -b main
    echo "one" > a.txt
    git add a.txt
    git commit -q -m "First"
    echo "two" >> a.txt
    git status -s

    What will this code print?

    Interview question

    Why does Git have a staging area?

    Exercise

    Create note.txt containing learn, add it, make a quiet commit named Add note, and print its subject.

    Expected output: Add note

    Git
    git init -q -b main
    echo "learn" > note.txt
    git log --format=%s

    Learn more from

    • Git: git-addgit-scm.com
    • GitHub Docs: Adding a filedocs.github.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousWhy version control?NextRead history and differences
    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.