Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Git

    What Never Goes Into Git

    .gitignore is a file listing patterns of files Git should never track.

    Chapter 10 of 113 min read

    The Plain Picture#

    Some things should never be in a shared photo album: your bank PIN, a photo of your passport, or a 50 GB video that makes the album impossible to carry.

    The Real Names#

    • .gitignore is a file listing patterns of files Git should never track.

    • Secrets — passwords, API keys, private keys, .env files (The Linux Command Line Ch 8) — must never be committed.

    • Git LFS (Large File Storage) stores big binary files (videos, datasets, model weights) outside the normal repository, keeping only small pointers in Git.

    Under the Hood#

    A typical .gitignore for StudyBuddy:

    .gitignore
    # secrets
    .env
    *.pem
    
    # Python
    __pycache__/
    *.pyc
    venv/
    .venv/
    
    # JavaScript
    node_modules/
    dist/
    .next/
    
    # OS / editor junk
    .DS_Store
    .idea/
    .vscode/

    .gitignore only affects untracked files. If a file is already tracked, adding it to .gitignore does nothing — you must also stop tracking it: git rm --cached .env (removes it from Git, keeps it on disk).

    If you commit a secret#

    Because every commit is in the history (Ch 3), deleting the file in a new commit does not remove the secret — it's still in the old commit, and in every clone. Bots scan GitHub for leaked keys continuously and can use them within minutes.

    The correct order:

    1. Revoke / rotate the secret immediately — create a new API key and disable the old one. This is the step that actually protects you. Assume the old one is compromised.

    2. Remove it from history with a tool like git filter-repo (or BFG), then force-push — and every teammate must re-clone. This is cleanup, not protection.

    3. Prevent it next time: .gitignore, and a secret scanner (GitHub secret scanning, gitleaks) in pre-commit hooks and CI.

    Gotchas

    • Why not commit node_modules/ or venv/? They're huge, machine-specific, and fully reproducible from package.json / requirements.txt (Python Packaging and Tools (coming soon)).

    • Large files bloat the repo forever, even after deletion, because history keeps them. Use LFS or external storage from the start.

    Check yourself

    3 questions
    1

    You add .env to .gitignore, but Git still shows it as modified. Why, and how do you fix it?

    Show answer

    It's already tracked; .gitignore only affects untracked files. Run git rm --cached .env and commit.

    2

    You pushed an API key to GitHub. What's the first thing you do?

    Show answer

    Revoke/rotate the key immediately.

    3

    Why doesn't deleting the file in a new commit solve the leak?

    Show answer

    The key is still in the earlier commit in the history, and in every clone.