Komitly
BlogPricing
Home/Blog/git init: Creating Your First Repository
BasicsBeginner

git init: Creating Your First Repository

Komitly·February 26, 2026·6 min read
git initrepositorygetting started
Loading article...

On this page

  • What is git init?
  • Creating your first repo
  • What's inside .git?
  • Your first commit
  • Doing it visually with Komitly
  • Common mistakes
  • Summary

Try it visually with Komitly

Stop memorizing commands. See your branches, commits, and merges in a beautiful visual interface.

Download Komitly — Free

Related articles

BasicsBeginner

git commit: Saving Your Work Step by Step

Master the git commit workflow. Learn how to stage files, write great commit messages, amend commits, and use visual staging tools.

git addgit commitgit commit --amend
8 min
BasicsBeginner

git status & git diff: Understanding What Changed

Learn how to inspect your repository with git status and git diff. Understand the three file states, read diff output, and review changes before committing.

git statusgit diffgit diff --staged
8 min
BasicsBeginner

git pull & git push: Syncing Your Code with the Team

Learn how to sync your local repository with a remote server. Understand git fetch, git pull, and git push, and handle common issues like rejected pushes and merge conflicts.

git fetchgit pullgit push
9 min

© 2026 Komitly

support@komitly.com
BlogPricingChangelogTermsPrivacy

What is git init?

Every Git repository starts with a single command: git init. It tells Git to start tracking changes inside the current folder. Under the hood, it creates a hidden.git directory that stores everything Git needs: your commit history, branch pointers, configuration, and the object database that holds every version of every file you have ever committed.

Without git init (or git clone, which runs it for you), a folder is just a folder. Git has no knowledge of it and no way to track changes. Running the command is a one-time setup step that transforms a plain directory into a fully functional version-controlled repository.

Think of git init as pressing the record button. Nothing is captured yet, but from this point on Git is ready to track every change you tell it about.

Creating your first repo

The most common workflow is to create a new project folder, navigate into it, and then initialize Git. Follow the three steps below to create your first repository from scratch.

Terminal
$ mkdir my-project
$ cd my-project
Terminal
$ git init
Initialized empty Git repository in /home/user/my-project/.git/
Terminal
$ ls -la
total 0
drwxr-xr-x 3 user user 60 Feb 26 10:00 .
drwxr-xr-x 10 user user 200 Feb 26 10:00 ..
drwxr-xr-x 7 user user 140 Feb 26 10:00 .git
$ git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)

That is all there is to it. You now have a fully operational Git repository. The .git directory was created automatically and your default branch (usually main) is ready for commits.

If you already have project files in an existing folder, you can skip the mkdir step and simply run git init inside that folder. Git will not modify any of your existing files.

What's inside .git?

You do not need to memorize the contents of the .git directory, but understanding the basics helps demystify how Git works. Here is what you will find inside a freshly initialized repository:

.git/ structure
.git/
  HEAD            # Points to the current branch (e.g. refs/heads/main)
  config          # Repository-level configuration
  description     # Used by GitWeb; you can usually ignore this
  hooks/          # Client- and server-side hook scripts
  info/           # Global exclude patterns
  objects/        # All content — blobs, trees, commits, tags
  refs/           # Branch and tag pointers
    heads/        # Local branches
    tags/         # Tag references

The two most important pieces are objects/ and refs/. The objects folder is Git's content-addressable database. Every file, directory snapshot, and commit you create is stored here as a compressed object identified by its SHA-1 hash. The refs folder holds pointers (branches and tags) that give human-readable names to specific commits.

The HEAD file tells Git which branch you are currently on. If you open it in a text editor right after git init, you will see something like ref: refs/heads/main.

Golden rule: never manually edit files inside .git unless you know exactly what you are doing. Let Git manage it for you.

Your first commit

An empty repository is not very useful. Let's create a file, stage it, and make your first commit. This two-step process — stage then commit — is the fundamental Git workflow you will repeat hundreds of times.

Terminal

Let's break down each command. First, git add:

$ git add README.md

Hover over each part to see what it does

And then git commit:

$ git commit -m "Initial commit"

Hover over each part to see what it does

After running these commands, Git has stored a permanent snapshot of your README.md file. You can change or even delete the file, and Git will still be able to restore this exact version at any point in the future.

Understanding the output

The output [main (root-commit) a1b2c3d] tells you three things: the branch (main), that this is the very first commit in the repository (root-commit), and the abbreviated SHA hash (a1b2c3d) that uniquely identifies this commit.

Doing it visually with Komitly

While the terminal is powerful, a visual Git client like Komitly makes it easier to understand what is happening. Instead of reading text output, you see your commit history as an interactive graph, and staging files is as simple as clicking a checkbox.

Here is what a small repository looks like after a few commits in Komitly's commit graph:

Komitly - my-project
c3d4e5fAdd basic stylingmain
b2c3d4eCreate index.html
a1b2c3dInitial commit

Each circle represents a commit. The branch label main shows you exactly where the branch pointer is. You can click on any commit to see the full diff, the author, and the timestamp.

When you are ready to make a new commit, the staging panel shows you exactly which files have changed and lets you move them between staged and unstaged with a single click:

Komitly - Staging
Staged (2)
Asrc/app.js
Apackage.json
Changes (2)
A.gitignore
MREADME.md
Add application entry point
Commit

Try clicking the files above to move them between the staged and unstaged sections. In the real app, you can also stage individual lines or hunks within a file, giving you fine-grained control over exactly what goes into each commit.

Common mistakes

Even experienced developers trip over these from time to time. Here are the most common pitfalls when initializing a Git repository:

  • Running git init in the wrong directory. If you accidentally initialize Git in your home folder or a parent directory, every file underneath becomes part of the repo. Always cd into your project folder first and double check with pwd.
  • Forgetting to create a .gitignore file. Without a .gitignore, you risk committing build artifacts, node_modules, or sensitive files like .env. Create one before your first commit.
  • Initializing inside another Git repo. Nested Git repositories cause confusing behavior. Before running git init, run git rev-parse --git-dir to check if you are already inside a repo.
  • Not making an initial commit. Some commands like git branch do not work until there is at least one commit. Always create an initial commit right after initializing.
  • Confusing git init with git clone. Use git init when starting a brand new project. Use git clone when you want a copy of an existing remote repository.

Summary

git init is the first command in every Git project. It creates the hidden .git directory that gives Git everything it needs to start tracking your files. Here is a quick recap of what we covered:

  • git init creates a new, empty Git repository in the current directory.
  • The .git folder contains objects (your file snapshots), refs (branch and tag pointers), and configuration.
  • After initializing, you stage files with git add and save snapshots with git commit.
  • A visual tool like Komitly lets you see your commit history as a graph and stage files with a click instead of typing commands.
  • Always create a .gitignore and make an initial commit right after running git init.

With your repository initialized and your first commit saved, you are ready to start building. Next, learn how to save your work effectively with git commit.