How to Create Your First Git Repository
In the last blog, we talked about why Git is important and how it solves project management challenges. Now, let’s take the first practical step: creating a Git repository.
Don’t worry—this series is not about using any specific programming language. We’ll work with plain English commands so you can focus only on Git itself.
Step 1: Create a Project Folder
Let’s start by creating a new folder for your project.
mkdir Project1
cd Project1
Here:
mkdir Project1creates a directory namedProject1.cd Project1moves inside the new folder.
This folder is just a plain directory right now. Git is not tracking it yet.
Step 2: Run git status
Let’s check the status:
git status
Output:
gaurav@learning-ocean:~/git-tutorials$ git status
fatal: not a git repository (or any of the parent directories): .git
You’ll see an error. Why? Because this is just a normal folder, not a Git repository yet.
Step 3: Convert the Folder into a Git Repo
To initialize Git inside this folder, run:
git init
gaurav@learning-ocean:~/git-tutorials$ git init
Initialized empty Git repository in /home/gaurav/git-tutorials/.git/
gaurav@learning-ocean:~/git-tutorials$
Once you do this:
- Your folder becomes a Git repository.
- Git starts tracking files here.
- All Git features (version history, commits, branching, etc.) are now available.
If you check again:
git status
The output will say there are no commits yet, which is correct because we haven’t added any files.
Step 4: Behind the Scenes – The .git Folder
After running git init, something new is created in your project directory:
ls -a
You’ll notice a hidden folder named .git.
This is where Git stores everything:
- File history
- Version information
- Metadata
In short, .git is the database of your project’s history.
⚠️ Git recommends you never directly edit the .git folder. Use Git commands instead.
But knowing about it helps you understand what’s happening behind the scenes.
Step 5: What If You Delete .git?
If you remove this folder:
rm -rf .git
Your project goes back to being a normal folder. Git status will again throw an error.
To make it a Git repository again, you’ll have to run git init once more.
Summary
In this lesson, we:
- Created a new folder for a project
- Saw why
git statusfails initially - Learned how
git initconverts a folder into a Git repository - Discovered the hidden
.gitfolder - Understood that deleting
.gitremoves Git tracking
🚀 Don’t Miss Out!
If you enjoyed this blog and want to learn Git step by step with me, then you’ll love what’s coming next.
👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.
👉 My YouTube Channel – More videos, more fun, and lots of learning!
👉 📺 Watch this topic in video form
Stay curious, keep coding, and let’s make learning fun together! 🎉