• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

git init: Initializes a new local Git repository

by admin

The “git init” command is used to initialize a new local Git repository in a specified directory. When you run this command, Git creates a new repository with the necessary data structures and configuration files to start version controlling your project.

Here’s how it works:

  • Repository Creation: Running “git init” in a directory sets up a new Git repository in that location. Git creates a hidden directory called “.git” where it stores all the necessary files and data related to version control.
  • Version Control Setup: The “.git” directory contains the repository’s metadata and object database. It is responsible for tracking changes, managing branches, storing commits, and maintaining the history of your project.
  • Configuration: Git initializes the repository with default configuration settings. This includes information such as the author’s name and email, default branch name (usually “master”), and other repository-specific settings.
  • Empty Working Directory: After initializing the repository, the working directory remains empty. It’s a clean slate where you can start adding files and making changes that Git will track.
  • Adding and Committing: To start tracking files in the repository, you need to use the “git add” command to stage them for the next commit. After adding files, you can create a commit using “git commit” to permanently save the changes to the repository’s history.

By running “git init” in a directory, you establish a new Git repository, allowing you to track changes, collaborate with others, and utilize Git’s powerful version control features. It is typically the first step when starting a new project or when you want to convert an existing project into a Git repository. Once initialized, you can continue to add, modify, and commit files to build a comprehensive version history for your project.

git init Command Examples

1. Initialize a new local repository:

# git init

2. Initialize a repository with the specified name for the initial branch:

# git init --initial-branch=branch_name

3. Initialize a repository using SHA256 for object hashes (requires Git version 2.29+):

# git init --object-format=sha256

4. Initialize a barebones repository, suitable for use as a remote over ssh:

# git init --bare

Filed Under: Linux

Some more articles you might also be interested in …

  1. compsize: command not found
  2. bc: An arbitrary precision calculator language (Command Examples)
  3. How to run “find” command on current directory only and not on sub-directories
  4. telinit Command Examples in Linux
  5. check-language-support Command Examples in Linux
  6. gnomon Command Examples
  7. clamscan: A command-line virus scanner
  8. CentOS / RHEL : How to create a Thinly Provisioned Logical Volume
  9. How to uninstall rbenv from Ubuntu
  10. kscreen-doctor : command not found

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright