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

    .gitignore and useful commit messages

    Exclude generated and sensitive files, and write understandable history.

    9 minutes2 games

    Not every file belongs in history: dependencies are generated, builds can be recreated, and secrets are forbidden. .gitignore holds patterns for untracked files: *.log for logs and dist/ for a directory.

    Git
    git init -q -b main
    echo "*.log" > .gitignore
    echo "secret" > debug.log
    echo "code" > app.js
    git status -s
    TrackIgnore

    src/, package.json, README

    node_modules/, dist/

    .env.example

    .env, private keys

    Shared config

    logs, temp files

    A commit subject should complete “If applied, this commit will …”, so Add password reset validation beats changes. Use an imperative subject; an optional body explains why.

    Important

    .gitignore does not untrack a known file. If .env was committed, remove it from the index and rotate the secret immediately; ignoring it after publication does not make it safe.

    What's the output?

    git init -q -b main
    echo "*.tmp" > .gitignore
    echo "draft" > notes.tmp
    echo "ship" > release.txt
    git status -s

    What will this code print?

    Interview question

    What if a secret enters Git history?

    Exercise

    Ignore .log, create app.js and debug.log, then show status; only .gitignore and app.js should appear.

    Expected output:
    ?? .gitignore
    ?? app.js
    Git
    git init -q -b main
    echo "code" > app.js
    echo "details" > debug.log
    git status -s

    Learn more from

    • Git: gitignoregit-scm.com
    • GitHub Docs: Ignoring filesdocs.github.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousRead history and differencesNextBranches and HEAD
    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.