First hands-on practice in Git: git init, file status (untracked, tracked, staged), git add and interactive patch mode, plus setting up .gitignore and the .gitkeep marker file.

In episode 2 you understood the three-area architecture: working directory, staging area, and repository. Now it is time to put that theory into practice: creating your first repository, reading file status, and understanding how a file becomes "known" to Git.
Throughout this episode you will hear four words that always appear in the Git world: untracked, tracked, modified, and staged. These four statuses are the everyday language of Git — master them, and all the following episodes will feel much easier.
Create a project folder, go into it, then run git init:
mkdir latihan-git
cd latihan-git
git initThe output will show a message like Initialized empty Git repository in .../.git/. At that moment, Git creates the hidden .git folder inside the project — this is the repository itself: the object database, config, and the entire commit history.
Warning
The .git folder is the heart of the repository. Never delete it — your repository disappears. Get in the habit of checking your working location with pwd before running git init so you do not create a repository in the wrong place.
Inside .git there are several important components:
| Component | Purpose |
|---|---|
objects/ | Git object database (blob, tree, commit) |
refs/ | Branch and tag pointers |
HEAD | Pointer to the currently active branch |
config | Repository (local) configuration |
index | Staging area (files that have been added) |
git status is the most frequently used command in Git. It shows the state of all files across the three areas.
git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)Now create some files and see how the status changes:
echo "<h1>Halo Dunia</h1>" > index.html
mkdir docs && echo "catatan" > docs/README.mdFile status falls into four categories:
??) — new files Git has never seen. M) — tracked files whose content changed in the working directory.A ) — changes already in the staging area, ready to be committed.git add <file> and git add .To tell Git that a file must be tracked, use git add:
git add index.html
git add docs/README.md
git add .git add <file> — marks one specific file.git add . — marks all changes in the current folder at once.After git add, the file moves from untracked to staged: Git records the file's content in the staging area and guarantees that exact version will be committed.
Tip
Professional teams more often use the specific git add <file> rather than the blanket git add ., especially for large changes. That way you are fully aware of what will go into the next commit.
Sometimes you want to mark only some lines of one file — for example, separating a bug fix from a feature addition. Interactive patch mode answers this need:
git add -p src/utils.js
Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? nThis mode shows changes per "hunk" (chunk) and asks one by one: y to accept, n to reject, e to edit the hunk manually. This is a key tool for keeping commits small and focused.
Not every file should go into Git — dependencies (node_modules), build artifacts, and environment files. The .gitignore file at the project root tells Git: never show or track these patterns.
node_modules/
dist/
*.log
.env
!.env.examplenode_modules/ — ignore a folder (with a trailing slash).*.log — wildcard: ignore all files ending in .log..env — ignore secret files.!.env.example — negation: re-include .env.example from the ignore rules.# are comments — add a short note for each block.Patterns that apply to all projects (e.g. the .DS_Store file on macOS) can be set once globally:
git config --global core.excludesFile ~/.gitignore_global
echo ".DS_Store" >> ~/.gitignore_globalGitHub also provides official .gitignore templates for almost every language and framework — take one as a starting point when creating a new project.
Git does not track empty folders — only files. To keep an empty folder structure (e.g. images/ or uploads/) in the repository, place an empty file named .gitkeep inside it. This file is only a conventional marker, with no special function in Git's eyes.
Episode 3 recap:
git init creates the repository and the .git folder containing the object database and config.git status distinguishes four statuses: untracked, tracked, modified, staged.git add <file> / git add . move changes into the staging area; git add -p selects line by line..gitignore keeps the repository clean of dependencies, artifacts, and secrets..gitkeep keeps empty folders included in Git.In episode 4 we make our first commit: permanently saving a snapshot with git commit, writing professional commit messages with Conventional Commits, reading history with git log, and fixing the last commit with --amend. The preparation you do here is the fuel for it. See you there!