Git for Beginners: Basics and Essential Commands
What Git is, the three places your work lives, and a first workflow from git init to your first branch

If you've ever had a folder that looks like this, you already understand the problem Git solves:
index.html
index-v2.html
index-final.html
index-final-REALLY-final.html
Every copy is a save point. None of them tell you what changed, why, or which one actually works.
Git replaces that folder with one clean project and a full history behind it. This guide covers Git basics for beginners: what Git is, the handful of terms you need, and a first workflow from an empty folder to your first branch. Every terminal output below is real, from Git 2.56.0.
What Git is
Git is a version control system: a tool that records snapshots of your project over time, so you can see what changed, go back, and try things without fear.
It's also distributed. Every copy of a Git project carries the complete history on its own. Your laptop doesn't need a server to commit, view history or switch versions. When you work with others, you share history between copies; nobody's copy is the only real one.
One common mix-up: Git is not GitHub. Git is the tool on your computer. GitHub is a website that hosts Git repositories so people can share them. You can use Git for years without ever touching GitHub.
Why developers use Git
- Undo with confidence. Every commit is a save point you can return to.
- See what changed, and why. Each commit records the exact changes, who made them, when, and a message explaining them.
- Try ideas safely. A branch lets you experiment without touching the working version.
- Work with other people. Several developers can change the same project and combine their work.
The core terms
Four words cover most of what you'll read about Git:
- Repository (repo): your project folder plus its entire history. The history lives in a hidden
.gitfolder inside the project. - Commit: a saved snapshot of your project at one moment, with a message and a unique ID (a hash like
523d7bc). A commit stores the whole project as it was, not just a list of edits. Git stores it efficiently, but you can think of every commit as a complete save point. - Branch: a named line of commits. The default one is usually called
main. A new branch lets you work on something without affectingmain. - HEAD: a pointer to where you are right now, normally the latest commit on the branch you're on. When you see
HEAD -> main, read it as "you are here, on main".
The three areas: why git add comes before git commit
The question nearly every beginner asks: why two steps? Why not save directly?
Because Git has three places your work can be:
Changes move from your files, to the staging area, to the repository.
- Working directory: the actual files you edit in your editor.
- Staging area: a holding area where you choose which changes go into the next commit.
- Repository: the permanent history of commits.
The staging area exists so a commit can be one meaningful change, not "everything I touched today". Fixed a typo and started a new feature in the same hour? Stage and commit the typo fix alone, then the feature separately. Your history stays readable, and undoing one doesn't undo the other.
git add moves changes into the staging area. git commit saves whatever is staged as a new snapshot.
Your first Git workflow, step by step
Open a terminal. Every command below can be typed exactly as shown.
1. Tell Git who you are (once per computer)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
Git attaches your name and email to every commit. The third line makes new projects start on a branch called main. Without it, Git 2.56 still names the first branch master and prints a long hint about the default changing in Git 3.0. main is what GitHub uses, so it's the less confusing choice.
2. Create a repository: git init
mkdir my-website
cd my-website
git init
Initialized empty Git repository in .../my-website/.git/
That .git folder is the repository. It's hidden, and you never edit it by hand. Here's what's inside, at a beginner level:
A local repository. Your files sit next to
.git, which holds the history.
Delete .git and the history is gone; your current files stay. That's the whole difference between "a folder" and "a Git repository".
3. Check what Git sees: git status
Create two files, index.html and style.css, with any content. Then:
git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html
style.css
nothing added to commit but untracked files present (use "git add" to track)
Untracked means Git sees the files but isn't recording them yet. git status is the command you'll run most. When in doubt, run it: it always tells you where things stand, and usually what to do next.
4. Stage your changes: git add
git add index.html style.css
You can also use git add . to stage everything in the current folder. Run git status again:
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html
new file: style.css
Both files are now in the staging area, waiting for a commit.
5. Save a snapshot: git commit
git commit -m "Add home page and styles"
[main (root-commit) 0793928] Add home page and styles
2 files changed, 8 insertions(+)
create mode 100644 index.html
create mode 100644 style.css
That's your first commit. 0793928 is the start of its ID; yours will be different, because the ID depends on the content, author and time. -m sets the message. Write messages that say what the change does: "Add home page and styles", not "update" or "stuff".
6. Change something, see the difference: git diff
Add a paragraph to index.html, then run git status:
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
To see exactly what changed:
git diff
diff --git a/index.html b/index.html
index 44e99bb..1a9d657 100644
--- a/index.html
+++ b/index.html
@@ -3,5 +3,6 @@
<head><title>My Website</title></head>
<body>
<h1>Hello, Git</h1>
+ <p>My first tracked change.</p>
</body>
</html>
Lines starting with + were added; lines with - were removed. Happy with it? Stage and commit:
git add index.html
git commit -m "Add intro paragraph"
7. Read the history: git log
git log --oneline
523d7bc (HEAD -> main) Add intro paragraph
0793928 Add home page and styles
Newest first. Plain git log shows the same commits with full IDs, author and date. (HEAD -> main) is the "you are here" marker.
8. Try an idea on a branch: git switch -c
git switch -c dark-mode
Switched to a new branch 'dark-mode'
Add a dark background to style.css, then git add style.css and git commit -m "Try a dark theme". The log on this branch:
6b85f46 (HEAD -> dark-mode) Try a dark theme
523d7bc (main) Add intro paragraph
0793928 Add home page and styles
Now switch back:
git switch main
git log --oneline
523d7bc (HEAD -> main) Add intro paragraph
0793928 Add home page and styles
The dark theme commit isn't on main, and style.css on disk is back to the version without it. The experiment still exists on dark-mode; main is untouched.
Commit history. Each commit points back to the one before it; branch names point at their latest commit, and HEAD points at the branch you're on.
The essential commands
| Command | What it does |
|---|---|
git init |
Turn the current folder into a repository |
git status |
Show what's changed, staged or untracked |
git add <file> |
Stage a file's changes for the next commit |
git add . |
Stage all changes in the current folder |
git commit -m "msg" |
Save the staged changes as a new commit |
git diff |
Show unstaged changes, line by line |
git log --oneline |
Show the commit history, one line each |
git branch |
List branches; * marks the current one |
git switch -c <name> |
Create a new branch and move to it |
git switch <name> |
Move to an existing branch |
Where beginners get stuck
git add . without looking. It stages everything, including files you didn't mean to commit. Run git status first, every time, and read the list.
Committing secrets. Passwords and API keys in a file like .env don't belong in a repository; once committed, they stay in the history even if you delete the file later. Create a file called .gitignore and list the files Git should never track:
.env
node_modules/
Git then leaves those files out of git status and git add ..
Messages like "fix" or "changes". In three weeks you'll want to know what each commit did. One clear sentence per commit pays for itself the first time you search the history.
The takeaway: Git is three areas and a handful of commands that move changes between them. Edit, add, commit, repeat, with git status whenever you're unsure.
The limit of this guide is that everything here happens on your own computer. Sharing work through GitHub (git push, git pull), and bringing a branch back into main (git merge), are the next steps, and they build directly on these commands.
Run through the eight steps once in an empty folder. Which Git message confused you first, and did git status help you work it out?
Comments
Join the discussionNo comments yet. Be the first to comment.




