Your first repository
init, add, commit — create a repo and save your first snapshot, entirely by hand.
- Turn a folder into a git repository with git init
- Explain the three places a change lives — working tree, staging area, history
- Save a snapshot with git add and git commit, by hand
The previous lesson covered why version control matters. This one is pure hands-on: you'll create a repository and save your first commit using nothing but the command line. No agent, no GUI — just you and git, so you can do this anywhere, on any machine, when you need to.
Start a repository
git init turns an ordinary folder into a git repository by creating a hidden
.git directory where all history is stored:
mkdir my-project
cd my-project
git initThat's it — you now have a repository. Nothing is being tracked yet; git is just watching the folder.
The three places a change lives
This is the mental model that makes git click. A change moves through three areas:
- Working tree — the actual files you edit. "What's on disk right now."
- Staging area (the "index") — a holding pen for the changes you want in your next commit. You choose what goes here.
- History — the permanent series of commits, once you commit what's staged.
The staging area is the part people miss. It lets you commit some of your changes and leave others for later — you assemble a commit deliberately rather than dumping everything at once.
Stage and commit
Create a file, then move it through the stages:
echo "# My Project" > README.md
git add README.md # working tree → staging area
git commit -m "Add README" # staging area → historygit addstages a change (usegit add .to stage everything at once).git commit -m "…"records everything staged as a new snapshot, with a message describing why.
Do it yourself: run those four commands (init, create a file, add,
commit) in a real terminal. Then run git log — you'll see your commit,
with its message, author, and a unique id. You just did the whole loop with no
tools but git.
Telling git who you are (once per machine)
Your first commit may prompt you to set your identity. It's a one-time setup:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"Where to go next
You can create a repo and save snapshots. Next: seeing what changed — how to inspect your working tree and history so you always know what you're about to commit.