git init

Estimated reading: 2 minutes 18 views

The git init command is used to create a new Git repository in a directory, enabling version control for your project. It initializes the repository and prepares the directory for tracking changes.

What Happens When You Run git init?

  • Creates a .git Directory: This hidden directory contains all the configuration and metadata Git uses to manage the repository.
  • Does Not Automatically Track Files: Files remain untracked until you explicitly add them using git add.
  • Prepares the Directory for Git Operations: After running git init, you can start using Git commands to track and commit changes.

How to Use git init

  1. Navigate to Your Project Directory and Initialize Git: Open the terminal, go to your project directory (or create one), and run git init to initialize the Git repository in that directory.

				
					mkdir my_project  # Optional: Create a new directory
cd my_project     # Navigate to the directory
git init          # Initialize Git repository

				
			

2. Check the Repository Status (Optional): After initializing, you can check the repository’s status using git status. Initially, it will show that no files are being tracked.

				
					git status

				
			

Conclusion

The git init command is the first step to turn a directory into a Git repository. Once initialized, you can start adding files, making commits, and using other Git commands to manage your project’s version control.

Leave a Comment

Share this Doc

git init

Or copy link

CONTENTS