Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git
init
initialize
repository

What is the git init command?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

A Git repository is a virtual storage place for your project that allows you to save versions of your code so that you can access them when needed.

The git init command is used to initialize a new git repository or reinitialize an existing one.

The git init command transforms the current directory into a Git repository, i.e., a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. It will also create a new master branch.

Running git init in an existing repository is safe, meaning that it will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates (or to move the repository to another place if the --separate-git-dir option is specified).

Example

To create a folder called myproject and transform it into​ a Git repository, we would need to execute the following commands:

mkdir myproject
cd myproject
git init

To create a file, run the cat or touch command, as follows:

touch code.txt

Then, add files to the repository using the git add command, as follows:

git add code.txt
git status

RELATED TAGS

git
init
initialize
repository
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring