Updated
Git’s daily loop is small: change files → stage → commit. Learn these three moves well and everything else builds on them.
Create a repository
mkdir hello-git && cd hello-git
git init
git init creates a hidden .git folder. That folder is the repository: every commit, branch and tag lives there.
The three areas
| Area | What it is |
|---|---|
| Working tree | The files you see and edit |
| Staging area (index) | The changes you’ve chosen to go in the next commit |
| Repository | The commits that are saved for good |
Make a commit
echo "# Hello Git" > README.md
git status # README.md is "untracked"
git add README.md # stage it
git status # now "Changes to be committed"
git commit -m "Add README"
Edit the file again and look at what changed before staging:
echo "Learning Git workflows." >> README.md
git diff # unstaged changes
git add README.md
git diff --staged # what will be committed
git commit -m "Describe the project"
Tip:
git add -pwalks you through each change one hunk at a time, so you can stage part of a file. It’s the best habit for clean commits.
Read the history
git log --oneline --graph --decorate
Each line is a commit with a short hash (e.g. 3f2a1c9). You’ll use these hashes to point at commits later.
Ignore files
Create a .gitignore so build output and secrets never get committed:
node_modules/
dist/
.env
.DS_Store
Write good commit messages
- A short summary (≈50 characters), written as a command: “Add login form”, not “added stuff”.
- A blank line, then the why if it isn’t obvious.
Next
Now that you can commit, it’s time for branching and merging.
One Git tip a week
Short, practical, no spam. Get the free printable Gitflow cheat sheet when you join.
Newsletter launching soon.