0
0
Gitdevops~5 mins

Creating a repository with git init - Step-by-Step CLI Walkthrough

Choose your learning style9 modes available
Introduction
When you want to start tracking changes in your project files, you need a place to store that history. Git helps by creating a repository, which is like a special folder that remembers all your changes.
When you start a new project and want to keep track of changes over time.
When you want to save versions of your work to avoid losing progress.
When you want to share your project with others using version control.
When you want to organize your code and collaborate with teammates.
When you want to prepare your project to be uploaded to a remote server like GitHub.
Commands
Create a new folder named 'my-project' to hold your project files.
Terminal
mkdir my-project
Expected OutputExpected
No output (command runs silently)
Change directory into the new project folder to work inside it.
Terminal
cd my-project
Expected OutputExpected
No output (command runs silently)
Initialize a new Git repository in the current folder. This creates a hidden folder where Git stores all version history.
Terminal
git init
Expected OutputExpected
Initialized empty Git repository in /home/user/my-project/.git/
List all files including hidden ones to confirm the '.git' folder was created.
Terminal
ls -a
Expected OutputExpected
. .. .git
-a - Show all files including hidden ones
Key Concept

If you remember nothing else from this pattern, remember: git init creates a hidden folder that starts tracking your project changes.

Common Mistakes
Running git init outside the project folder
Git will create the repository in the wrong place, causing confusion and misplaced files.
Always navigate into your project folder before running git init.
Not checking for the .git folder after init
You might think the repository was not created and run commands that fail.
Use ls -a to confirm the .git folder exists after git init.
Summary
Create a project folder and move into it.
Run git init to start a new Git repository.
Verify the repository by checking for the hidden .git folder.