src: Author

Version Control with Git — 2#Getting Started with ‘git init'

Rahul S
2 min readAug 15

--

One of the fundamental steps in utilizing Git effectively is creating a repository. In this tutorial, we will dive into the git init command, which is used to set up a new Git repository from scratch. By the end of this tutorial, we intend to have a clear understanding of what git init does and how it sets the foundation for our version control journey.

What is git init?

git init is a command-line operation that initializes a new Git repository. It sets up all the necessary files and directories that Git uses to manage version control.

Essentially, running git init prepares your project directory to be tracked by Git, enabling you to start making commits, tracking changes, and collaborating effectively with others.

Creating Your First Git Repository

Let’s break down the process of creating a Git repository using the git init command step by step.

Step 1: Open a Terminal: Before you begin, ensure you have a terminal or command prompt open and navigate to the directory where you want to create your new Git repository.

Step 2: Initialize the Repository: Run the following command:

git init

This command initializes a new, empty Git repository in the current directory.

Step 3: Repository Setup: After executing the git init command, Git sets up a special hidden directory called .git in your project directory. This directory contains all the necessary configuration files and subdirectories for version control.

Here’s a brief overview of the contents of the .git directory:

  • config file: Stores project-specific configuration settings, such as email addresses and custom preferences.
  • description file: Used by certain Git programs like GitWeb; you can typically ignore this.
  • hooks directory: Used for client-side and server-side scripts that can be triggered by Git’s events.
  • info directory: Contains global exclusion rules for files that should not be tracked.
  • objects directory: Stores all the commits you make.

--

--

Rahul S

LLM, NLP, Statistics, MLOps | Senior AI Consultant | IIT Roorkee | Connect: [https://www.linkedin.com/in/rahultheogre/]