git init command

The git init command is used to create a new blank local git repository or reinitializing the existing one. It is used to make an existing project as a Git project. Several Git commands run inside the repository, but git init command can be run outside of the repository.

Bash

git init

The default branch name is master.

Initialize Repo with Specified Branch name

Bash

git init -b <branch-name> or git init --initial-branch= <branch-name>

The command git init -b main is used to initialize a new Git repository with a specified default branch name (main in this case).

This command is useful when we want to create a new Git repository and set a different default branch name instead of the default branch name, which is usually master.

Create Directory and Initialize it

The following command will create a directory named Demo and initializes the Demo directory as a git repo.

Bash

git init Demo

Note: Initializing as a git repo will create a .git directory in the folder that holds all necessary repository files.

Remove Git Repository

The following command is used to remove the .git folder which means the repo is no longer a git repo.

Bash

rm -rf .git

The command rm -rf .git is used to forcefully remove the entire Git repository, including all its files and history. It's a dangerous command and should be used with caution because it irreversibly deletes the Git repository.

If we run this command in a directory containing a Git repository, it will remove the repository and all its version history. Make sure we have a backup or are absolutely certain that we want to delete the repository before using this command.