Git: Beginner to Advanced
Your first repository
Create a repository and make a clean first commit.
Lesson 2 of 12
Reading: about 6 min
Lesson + practice: about 12 min
Difficulty: Beginner
On this page5 sections
Create a repository and make a clean first commit. Follow the animated example, then use the sections below to review each idea.
Visual walkthrough
Use the player controls or jump menu to inspect each step. The diagram changes as the example moves forward.
The player shows one focused example. The sections below explain the ideas behind each topic.
Every Git project starts the same way: turn a folder into a repository, tell Git which files belong in it, and save the first snapshot. Doing this carefully at the start keeps clutter such as dependencies, logs and secrets out of your history for good.
This lesson sets up the study planner project used throughout the course. Your folder paths and commit IDs will differ from the ones shown.
git init and git status
git init creates a hidden .git folder that will hold the whole history. Your own files are not changed. git status is the command you will run most often: it tells you which branch you are on and what Git sees in the folder.
Start a repository
Run these inside your project folder. No commits yet means the history is empty; nothing has been saved.
git init
git status$ git init
Initialized empty Git repository in /home/alex/planner/.git/
$ git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)Untracked and ignored files
New files start as untracked: Git can see them but is not saving their history. The short status marks them with ??. Here the project also contains a node_modules folder of installed packages and a debug.log, which should never be committed.
See what Git notices
Four untracked entries. node_modules/ is shown as one folder.
git status --short?? README.md
?? app.js
?? debug.log
?? node_modules/A .gitignore file lists patterns for files Git should leave alone. A pattern ending in / matches a folder; * matches any characters.
Ignore generated files
After adding the rules, the log file and the packages folder disappear from status. --ignored shows them again, marked !!, so you can confirm what is being ignored.
cat .gitignore
git status --short
git status --short --ignored$ cat .gitignore
node_modules/
*.log
$ git status --short
?? .gitignore
?? README.md
?? app.js
$ git status --short --ignored
?? .gitignore
?? README.md
?? app.js
!! debug.log
!! node_modules/$ git rm --cached .env
rm '.env'
$ git status --short
D .env
?? .gitignoreIf the file held a secret such as a password or API key, it is still in your old commits. Change the secret straight away.
git add and git commit
git add chooses what goes into the next snapshot. Naming files one by one is the safest habit for a first commit, because nothing slips in by accident. git commit then saves the staged snapshot with a message.
Stage the files you want
Changes to be committed lists exactly what the commit will contain: three new files, and nothing from the ignored ones.
git add README.md app.js .gitignore
git status$ git add README.md app.js .gitignore
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: README.md
new file: app.jsSave the first snapshot
root-commit marks the first commit in the history. Afterwards, working tree clean means everything in the folder matches what is saved.
git commit -m "Add README, app and ignore rules"
git status$ git commit -m "Add README, app and ignore rules"
[main (root-commit) 274d1aa] Add README, app and ignore rules
3 files changed, 4 insertions(+)
create mode 100644 .gitignore
create mode 100644 README.md
create mode 100644 app.js
$ git status
On branch main
nothing to commit, working tree cleanRead history with git log
git log lists commits from newest to oldest. Each entry shows the full commit ID, who made it, when, and the message.
Read the full log
The long hexadecimal string is the commit's unique ID. You can refer to a commit by the first seven or so characters, such as 274d1aa.
git logcommit 274d1aa36d2def82cab358fb7d7125679dd4e6bb
Author: Alex Bennett <alex@example.com>
Date: Tue Oct 20 09:01:00 2026 +0100
Add README, app and ignore rulesA compact view
After one more commit, --oneline shows one line per commit, newest first. This is the view you will use most day to day.
git log --onelinee5bcdef Describe the project
274d1aa Add README, app and ignore rulesIn a long history, the log opens in a pager. Press the space bar to scroll and q to quit.
You add *.log to .gitignore, but app.log still shows as modified in git status. Why?
Reveal answer
app.log was committed before the rule existed, so Git is still tracking it. Ignore rules only apply to untracked files. Run git rm --cached app.log and commit to stop tracking it.
What does ?? mean in git status --short?
Reveal answer
The file is untracked: Git sees it in the folder but has never saved it. Stage it with git add to include it in the next commit, or add it to .gitignore if it should never be committed.
Your progress
Reveal the check answer or reach the end to complete this lesson.