Git and GitHubgit 2.54 · GitHub · macOS, Linux or Windows
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
26 small wins to finish your pathNext lesson →

Your first repository

A Git repository is an ordinary folder with a hidden .git folder inside it, and that hidden folder is where every commit, branch and setting for the project is stored.

Last updated: 12 Oct, 2026 · git 2.54

Git works per folder. Until you run git init in a folder, Git knows nothing about it and no command works there. One command turns the folder into a repository, and nothing outside the folder is touched.

Running git init and the hidden .git folder · from the Git and GitHub series · 4:15 to 4:53

Syntax: git init -b <name> creates the repository in the folder you are standing in and names its first branch.

bash
git init -b main    # -b names the first branch; without it Git uses init.defaultBranch
Project files used on this pageThis lesson builds on a project from earlier lessons. The code below imports this file. Click a file to see its code, or follow the link to the lesson that wrote it. To run the code yourself, keep it in the same folder.
View the code here
.gitconfig
[user]
	name = Reader
	email = reader@example.com

Creating the folder and running git init

Make an empty folder, step into it, and initialise it. The project in this course is called ask-docs.

ExampleAPI keyA new repository in an empty folder; the path Git prints is your own folder
mkdir ask-docs && cd ask-docs
git init -b main

The path in the answer is where the repository lives. -b main names the first branch main. Without -b, Git uses the init.defaultBranch setting, and when that is not set it falls back to master and prints a hint saying so. Running git init twice in the same folder is harmless: it reports that the repository was reinitialised and keeps your commits.

Those two lines are the throwaway repository the rest of this page works in, and the blocks below start from them without showing them again. If you are following along in one folder, run them once and skip them after that. Adding -q to git init keeps it quiet, which is useful once you know what it says.

Looking inside the .git folder

The folder looks unchanged in a file manager, because .git starts with a dot and is hidden. ls -a lists hidden entries too.

ExampleThe hidden folder that git init created
ls -a

Only .git is new, and the folder holds nothing but that. Everything Git keeps for the project sits inside it, which ls .git lists.

ExampleWhat Git stores inside .git
ls .git

Those entries are Git's own storage:

  • HEAD is a one-line file naming the branch you are on.
  • config holds the settings for this repository alone, the --local level.
  • objects is where the content of every commit ends up.
  • refs holds one small file per branch and tag, each naming a commit.
  • hooks and info and description are for scripts and notes, and you can leave them alone.

You never edit these by hand. The only thing worth remembering is that deleting .git deletes the whole history and turns the project back into a plain folder, while leaving your current files untouched.

Reading status in an empty repository

git status is the command you run most. In a repository with no commits and no files it already says three useful things.

ExampleStatus in a repository with nothing in it yet
git status
  • On branch main names the branch, so the -b main worked.
  • No commits yet means the history is empty. The first commit is called the root commit.
  • nothing to commit with the hint about git add is Git saying the folder is empty. The next page fills it.
The ask-docs folder seen as a repository. The folder holds the files you edit, README.md, prompt.txt and loader.py, and a hidden .git folder. Inside .git are HEAD, which names the current branch, config with this repository's settings, objects holding the content of every commit, and refs holding one file per branch.

A plain folder compared with a repository

A plain folderA repository
Keeps old versionsOnly what you copied by handEvery commit you made
Says what changedNoYes, line by line
Works offlineYesYes, the history is local
Extra storageNoneThe .git folder, usually small
Can be shared with historyNoYes, by pushing it to GitHub

Where you run git init

  • A project you are starting. Make the folder, run git init -b main, commit early.
  • A folder of code you already have. Initialising it keeps the files as they are and puts them all in the first commit.
  • A folder you plan to put on GitHub. You can also clone an empty repository from GitHub instead, which the GitHub part covers.
Watch out. Run git init in the project folder, not in your home folder. A repository in your home folder tries to track every file you own, and git status becomes a page of noise. A repository inside another repository is also trouble: the outer one stores the inner folder as a single unreadable entry. If you make that mistake, delete the .git folder you created and start again in the right place.
Try it yourself
  • Run git status in a folder that is not a repository. Git answers fatal: not a git repository, which is how you tell the two apart.
  • Run git init without -b main in another empty folder and read the branch name in git status.
  • Create a file in the folder, delete the .git folder with rm -rf .git, and run git status again. The file survives, the repository does not.

You understood something today that you didn't yesterday.