CodeBlanks Logo Icon CodeBlanks

git init

Learn to create a new repository with git init.

A new repository

The place where Git keeps its history is called a repository. The git init command turns the folder you are in into a new repository. When you run it you see a message like Initialized empty Git repository.

mkdir oyun
cd oyun
git init

From that moment every change in the oyun folder can be saved.

The .git folder

When git init runs, a hidden .git folder appears. All of Git's records stay inside that folder while your own files stay in the folder above. If you delete the .git folder the repository and its history are lost.

ls -a
.  ..  .git

The next lesson looks inside this folder.

Practice Build the first repository

Create a folder named proje and move into it. Start a repository there in quiet mode, then print depo hazir to the screen.

Starter code

terminal
# 1) proje adinda bir klasor olustur
# 2) o klasore gir
# 3) depoyu sessizce baslat
# 4) ekrana depo hazir yazdir

Sample solution

terminal
mkdir proje
cd proje
git init -q
echo depo hazir

Expected output

depo hazir

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What happens when you run git init in an empty folder?

  • A new repository with a hidden .git folder appears Correct answer
  • A connection to a remote Git server is made
  • The folder and all its files are deleted
  • Files start being saved automatically

Explanation: git init only builds the repository structure; it creates the .git folder but does not save your files. Saving them takes the later steps.

2 Start the repository

Question
mkdir oyun
cd oyun
git ____
Answer
mkdir oyun
cd oyun
git init

Explanation: The subcommand that creates a new repository is init; there is no start, new or create subcommand.

3 Repository concepts

Term Meaning
git init Creates a new repository
repository A folder with history
.git Where Git keeps data
distributed model Full copy on each machine

All lessons in Beginner