Course outline · 0% complete

0/28 lessons0%

Course overview →

git init and git status

lesson 2-1 · ~9 min · 3/28

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.

$ 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

First, the opening line, because it contains a word we haven't 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 (unit 5); until then main is the only one, so read On branch main simply 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 untracked. Notice how the output even tells you the next command to run. Git's messages are unusually helpful, read them.

Try it yourself in this simulated shell. You've just made a folder called recipe-book and moved into it. Follow the steps.

Step 1/3: Turn this folder into an empty Git repository.

~/recipe-book $ 

Quiz

You run git init in an empty folder and immediately run git log. What happens?

Quiz

git status lists pancakes.txt under "Untracked files". What does that mean?

Code exercise · bash

Your turn, terminal warm-up. Build the project folder we'll pretend to track: create recipe-book, cd into it, create pancakes.txt containing the four lines shown in the expected output (use printf with \n), make an empty folder called notes, then run ls and cat pancakes.txt.

Problem

You are inside a brand-new project folder. Which exact command turns it into an empty Git repository?