The git init
is a command we use to initialize git on a directory. Think of it as setting up a new directory that Git will watch over, keeping track of all the changes we make to the files inside it. We can use the git init
command to initialize a new project or track the changes on an existing project. To do this,
- Open the terminal. (Git Bash application if you are using git natively in Windows)
- Create a new directory if you are starting with a new project:
mkdir directory-name
. You can skip this step if you want to initialize git on an existing project/directory.
- Navigate inside the directory where you want to initialize Git:
cd directory-name
.
- Initialize Git:
git init
.
By running the git init
command, Git creates a hidden directory called .git in our project directory. This .git
directory is where Git stores all the information about our project's history and changes. We will work with this directory only in rare cases, but it's important that it stays there.
Now Git has been initialized inside our project directory and it will start tracking all the changes we make within the directory.