Git basics

Git is a version control system: it records snapshots of your project so you can see what changed, go back to any earlier state and work with other people without emailing project_final_v3_FINAL.zip around.

One-time setup

Git stamps every commit with your name and email, so set them before your first commit.

git --version
git config --global user.name "Ananya Iyer"
git config --global user.email "ananya@example.in"
git config --global init.defaultBranch main
git config --list

The three areas

Area What it holds Moves forward with
Working directory The files you are editing right now Your editor
Staging area (index) The changes you have chosen for the next snapshot git add
Repository (.git) The permanent chain of commits git commit

Staging is what makes Git different from a simple backup: you decide which changes belong together, so one commit can be "fix GST rounding" without dragging in half-finished work on another feature.

Your first repository

mkdir sweets-billing && cd sweets-billing
git init
# create invoice.py, README.md ...
git status                    # untracked files in red
git add invoice.py README.md  # or: git add .
git status                    # staged files in green
git commit -m "Add invoice total calculation"
git log --oneline

git status is the command you will run most often. Run it after every step until the workflow is automatic.

Seeing what changed

git diff                # working directory vs staging area (unstaged edits)
git diff --staged       # staging area vs last commit (what you are about to commit)
git log --oneline -10   # short history
git log -p invoice.py   # full history of one file, with diffs
git show 9f2c4ab        # everything about one commit

Each commit has a 40-character SHA hash; the first seven characters are enough to refer to it.

Writing commit messages people can use

A good message explains why, in the imperative mood, under about 50 characters for the summary line.

Good:  Add 18% GST breakup to invoice PDF
Good:  Fix crash when customer has no GSTIN
Poor:  changes
Poor:  final fix 2 working now pls check

Commit often, in small logical units. Ten small commits tell a story; one giant "day's work" commit tells nothing and is impossible to revert cleanly.

Handy extras

git add -p                 # stage selected hunks of a file, interactively
git commit -am "Message"   # stage all tracked changes and commit in one step
git mv old.py new.py       # rename, already staged
git log --graph --oneline --all

Common mistakes

  • Running git init inside your home folder or Downloads and accidentally tracking everything.
  • Committing .env, db.sqlite3, .venv/ or __pycache__/ because no .gitignore exists yet.
  • Using git add . blindly without reading git status first.
  • Treating commits as saves: commit a working, meaningful unit, not every keystroke.

Practice

Create a folder for a small billing script, run git init, and make three commits: the empty script, the GST calculation, and a README. Between the second and third, use git diff and git diff --staged to see the difference between them, then read your history with git log --oneline --graph.

B

Written by Bablu Kumar Jha

Founder, BeeProton AI · Mumbai, Maharashtra, India