• 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. consul: Distributed key-value store with health checking and service discovery
  2. phar Command Examples in Linux
  3. rusnapshot: command not found in Linux
  4. CentOS / RHEL 7 : Booting process
  5. tcptraceroute: command not found
  6. iptables Command Examples in Linux
  7. btrfs device Command Examples in Linux
  8. deluge-console: An interactive interface for the Deluge BitTorrent client
  9. How to Configure Proxy in CentOS/RHEL/Fedora
  10. “docker logs” Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright