Basic

The folder nobody sees

The first time I typed `git init` I waited for something to happen. Nothing did. Then I found a `.git` folder hiding in the directory, and the whole thing finally made sense.

What you will see

[main (root-commit) abc1234] Add a note 1 file changed, 1 insertion(+) create mode 100644 note.txt

About 2 min of reading

Try It

A command that changes a plain folder into a repository, in about five keystrokes, then nothing visible happens. Let me watch a couple of commands actually do it and see what the folder becomes.

1

Open a terminal and drop into a folder I don’t care much about. Git only ever works inside the folder I type it into, so start in a place that has something in it, a script, a document, a blank slate either way.

mkdir git-tut cd git-tut

Before you run it, say out loud what it will print. Then open the answer.

What it prints
C:\Users\You\git-tut>
Type cd and then the folder name, not a full path. If the folder lives somewhere else, cd into it first. git init always plants the folder where the terminal already is.
2

Run the command I have been talking about throughout the whole lesson. Nothing prints. No splash screen, no menu, no success banner. That silence is the whole trick, git is doing its work in a folder you cannot see yet.

git init

Before you run it, say out loud what it will print. Then open the answer.

What it prints
C:\Users\You\git-tut>
3

Look for proof that something happened. There is none on screen, so I look on disk. ls -la lists everything in the folder, hidden entries included, and there it is: a .git folder that was not there a second ago.

ls -la

Before you run it, say out loud what it will print. Then open the answer.

What it prints
drwxr-xr-x 1 You 1024 Aug 9 . drwxr-xr-x 1 You 1024 Aug 9 .. drwxr-xr-x 1 You 1024 Aug 9 .git
On Windows, Explorer hides `.git` by default. `ls -la` from a shell shows it either way, don’t go poking around the file picker and conclude the command failed. It didn’t.
4

That folder is the whole lesson in one line. Every commit, every branch, every tag git ever makes from here lives inside .git. I delete it, the history disappears. I copy it, the history moves with the project. The folder I named is irrelevant; the folder I cannot name is the repository.

git status

Before you run it, say out loud what it will print. Then open the answer.

What it prints
On branch main No commits yet Untracked files: (use "git add ..." to include in what will be committed) nothing here nothing added to commit but untracked files present (use "git add" to track)
Reading that output now is pointless, there is nothing staged and nothing committed yet. It only makes sense once you type the next command, `git add`.
5

Git will not let you commit without a name, and it will not tell you in advance. My first commit just exploded with a plain error. Set a name and email once and it never bugs you again, the --global flag means every project on the machine shares it.

git config --global user.name "Your Name" git config --global user.email "you@example.com"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
C:\Users\You\git-tut>
If you forget this before your first commit, the error says something about not knowing who you are. It is not dramatic, just run the two lines above and start over.
6

Now stage one file and take the snapshot. git add moves a chosen change into the staging area, then git commit seals it into history with a message describing it. Read the message back out later and it tells you what you were thinking that day.

echo "hello" > note.txt git add note.txt git commit -m "Add a note"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
[main (root-commit) abc1234] Add a note 1 file changed, 1 insertion(+) create mode 100644 note.txt
The hash in the success line, abc1234 above, is different every time. Ignore it for now; `git log` is where you come back to read history.

Put it in order

Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.

Data Flow

`git init` plants a hidden `.git` folder, and every command after that reads from and writes to it.
1 Open a project folder
↓
2 Run git init
↓
3 Git creates the .git folder
↓
4 Future commands store history inside it
Why this works
Git stores snapshots, not diffs

A common guess is that git remembers the changes between commits. It doesn't. Each commit is a full snapshot of the project at that moment. The .git folder is clever about wasting little space, identical files are stored once, and similar ones are stored as tiny deltas, but the mental model that helps beginners is: every commit is a photo of the whole folder.

Config, set once

The name and email above are the most important config you will ever touch. After that, git defaults are fine. A couple of flags worth knowing from day one:

git config --global init.defaultBranch main

This just means new repos start on main instead of master, which saves a rename later.

Examples

One command, no ceremony

git init

That's it. No folders chosen, no menu, nothing drawn. git init just creates a hidden .git directory in the current folder and calls it a day. Everything git ever does from here lives inside that folder.

Where did it go?

ls -la

On Windows you won't see .git in Explorer either, you have to show hidden files. The command above does. The .git folder holds every snapshot, every branch, and the config. Delete it and the history is gone; move it and the history moves with it. That single folder is your repository.

Git refuses to commit without a name

git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"

Before I set this, my first commit exploded with an error:

please tell me who you are.

Configure the user name 'user.email'...

Git will not record a commit it can't attribute. The --global flag sets the default for every project on this computer. You set it once, then never think about it again.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

Next Lesson
Choosing what to save
Choosing what to save →