git init
git init: initialize a new Git repository.
git init is a command to create a new Git repository. It initializes a new repository in the current directory, creating a hidden directory called .git that contains all the necessary files for the repository.
When you run git init, Git sets up the necessary data structures and files to start tracking changes in your project. This command is typically used when you are starting a new project or when you want to convert an existing project into a Git repository. Note that the repository starts empty, and you need to add files to it using git add and git commit.
Examples
Let's say you have a new project called my-awesome-project and you want to start using Git for version control.
Create a new directory for your project and prepare it for version control:
mkdir my-awesome-projectcd my-awesome-projectgit init
After running git init, you'll see a message like this:
Initialized empty Git repository in /path/to/my-awesome-project/.git/This is a sign that your project directory is now a Git repository. Your project directory is now set up as a Git repository, and you can start tracking changes to your files.
Begin tracking your project with an initial commit:
echo "# My Awesome Project" > README.mdgit add README.mdgit commit -m "Initial commit"
With these steps, you have successfully initialized a new Git repository and made your first commit. You can now continue working on your project, creating new branches, and collaborating with others using Git.