Lesson 2 of 7 in Basics

A new repository

Story: Pim keeps the Agency's archive, and nothing goes in without a repository to hold it.

A repository is a folder whose history git keeps. Git stores that history in a hidden folder called .git, inside the project's folder. You never change .git yourself: git commands do that for you.

Making a repository

git init makes the folder you're in a repository. Your files stay exactly as they were: git only adds the .git folder. ls doesn't show it, because names that start with a dot are hidden, but ls -a does.

git init <folder> makes a repository in another folder instead, and creates that folder first if it doesn't exist.

Run git init once per project, in the project's top folder. Running it again in a repository is harmless: git says Reinitialized existing Git repository and changes nothing. Running it in the wrong folder isn't harmless. A repository in your home folder would treat every file you have as part of one project, so check where you are with pwd first.

A new repository has no commits yet. You're already on the branch main, but the Live Graph has nothing to draw until you make the first commit. On your own computer, git calls that first branch master unless you've told it otherwise: git config --global init.defaultBranch main makes every new repository start on main, as it does here.

Asking git what it sees

git status is the git command you'll use most. It only looks and never changes anything, so run it whenever you're unsure. It tells you:

  • which branch you're on;
  • whether there are any commits yet;
  • which files git sees but doesn't keep yet. These are untracked.

Git finds the repository by looking in the folder you're in, then in each folder above it. So git status works from any folder inside a project. Outside a repository, it says so:

fatal: not a git repository (or any of the parent directories): .git

That's the quickest way to find out whether a folder is a repository.

Command What it does
git init Makes the folder you're in a repository.
git init <folder> Makes <folder> a repository, creating the folder if needed.
git status Shows the branch you're on and what git sees in your files. It changes nothing.

In the next Lesson, git add and git commit save your files in the repository.

New commands

  • git init
  • git status

Explainer: Making a repository

recipes: your repo, you are herebcc4f04 Add the pancake recipebcc4f04HEAD → main
The repository at the end of the Explainer.
Graph as text

recipes: your repo, you are here

  • HEAD → main at bcc4f04 "Add the pancake recipe"

Branches and tags

  • main at bcc4f04 "Add the pancake recipe"

Commits, newest first

  1. bcc4f04 "Add the pancake recipe"; no parent; refs: HEAD → main

Challenge 1 of 2

Story: Every record needs a home, Agent. Give these recipes one.

You're in a folder called recipes, which holds two recipes. Make it a git repository.

Commands 0 of Par 1

Goal

  • Not met yet: The files under ~ match the goal
  • Not met yet: HEAD is on branch main
  • Not met yet: The recipes folder is a git repository

Hints

Live Graph

No repository to show yet.

Terminal

~/recipes $