Creating a repository
In lesson 1-2 you learned that a repository is a folder Git is watching. Turning a folder into one takes a single command: git init.
$ mkdir recipe-book
$ cd recipe-book
$ git init
Initialized empty Git repository in /home/you/recipe-book/.git/This is how every project you will ever own starts its history: engineers run git init (or git clone, unit 7) within minutes of creating anything new, because Git can only protect what happens after it starts watching.
That's the whole ceremony. Git created the hidden .git folder (check with ls -a) and is now watching. Nothing is saved yet, an empty repository has zero commits.
One note about this course: Git commands appear two ways here. Fenced transcripts like the one above show $ lines (what you type) followed by Git's replies. And simulated practice terminals, like the one further down, let you type the commands yourself, step by step. Git is also preinstalled on macOS and most Linux systems, so everything works on your own machine too.
git status, your dashboard
git status answers the question "what does Git see right now?" You will run it constantly, before and after almost everything else.
$ echo "Pancakes" > pancakes.txt $ git status On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) pancakes.txt nothing added to commit but untracked files present
Start with the opening line, since it contains a word not yet defined. A branch is a named line of work inside the repository, and git init starts every repository with exactly one, named main. Branches get a whole unit later, so until then read On branch main as "you are on the default line of work."
Untracked means Git can see the file sitting in the folder but is not recording its versions yet. New files always start this way, because Git never assumes that everything in a folder belongs in the project. Build output, editor swap files, and downloaded archives all live alongside real source files, and only you can say which is which.
Notice that the output names the next command to run. Git's messages are unusually helpful about this, and reading them rather than skimming past them saves a great deal of guessing.
A recorded session
The session below starts in a folder called recipe-book that has just been created. Each step shows the command and the output it printed.
Step 1. Turning the folder into an empty Git repository.
~/recipe-book $ git init
Initialized empty Git repository in /home/you/recipe-book/.git/Step 2. Listing everything in the folder, including hidden entries, to spot the new .git folder.
~/recipe-book $ ls -a . .. .git
The same thing can be written as ls -la or ls -al or ls -A.
Step 3. Asking Git what it sees right now.
~/recipe-book $ git status On branch main No commits yet nothing to commit (create/copy files and use "git add" to track)
Running git log immediately after git init in an empty folder makes Git report that there are no commits yet.
The reason is that init and commit do entirely different jobs. git init creates the hidden .git database and starts watching, and that is all it does. History begins at the first git commit, so a brand-new repository holds zero snapshots and git log has nothing to print.
Worth noting is that nothing external is involved in any of this. The repository is complete and functional on your own disk from the moment init finishes, and no account, network connection, or hosting service is required to start recording history.
When git status lists pancakes.txt under "Untracked files", it means the file exists in the folder but Git is not yet recording its versions.
Untracked is best read as present but not under version control. Git can see the file, which is why it appears in the report at all, and it is telling you that it currently has no history for it and would lose nothing if the file changed.
Git never starts tracking a file on its own. Doing so requires git add, which is the subject of the next lesson, and that deliberate step is what keeps temporary and generated files out of a project's history by default.
Building the project folder
A terminal warm-up with no Git involved. This creates the project we will start tracking, using the commands from the terminal course.
mkdir recipe-book
cd recipe-book
printf "Pancakes\n- flour\n- eggs\n- milk\n" > pancakes.txt
mkdir notes
ls
cat pancakes.txtOutput
notes pancakes.txt Pancakes - flour - eggs - milk
printf is doing the interesting work here. It converts each \n into a real line break, so one command creates all four lines, where four separate echo calls with >> would have been needed otherwise.
The ls output is alphabetical, which is why notes comes before pancakes.txt. One detail to carry into the next lesson: the notes folder is empty, and Git tracks files rather than folders, so an empty directory is something Git will simply not see.
The command that turns a brand-new project folder into an empty Git repository is git init.
It creates the hidden .git folder inside the current directory, which is what makes that directory a repository. Being in the right folder matters, since init acts on wherever you are standing.
This is a once-per-project command. Running it again in an existing repository is harmless but pointless, and running it by accident in a parent directory is a genuine nuisance, because you end up with a repository wrapping several unrelated projects.