Tour of Git
Git Basics / Lesson 1.2

git init — Creating a Repository

Every Git journey begins with git init. This command creates a new Git repository in the current directory.

What happens?

When you run git init, Git creates a hidden .git directory that stores all the tracking information. Your files aren't affected — Git just starts watching.

Try it!

In the terminal on the right, initialize a new repository and create your first commit:

  1. Run git init to create a repository
  2. Create a file: echo "Hello Git" > hello.txt
  3. Stage the file: git add hello.txt
  4. Commit it: git commit -m "Initial commit"

Common Mistakes

Initializing in the wrong directory — Always make sure you're in the right folder before running git init. Running it in your home directory can cause confusion.

Forgetting to add files before committing — git init only creates the repository. You still need to git add files before you can git commit.

🎯

Goal

Initialize a new repository and make your first commit with a file called hello.txt

Terminal
$

No commits yet. Run `git init` and create your first commit.