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-project
cd my-awesome-project
git 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.md
git add README.md
git 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.
Hi! I'm Alex, creator of GitByBit.
And this is Gitopedia—a reference that summarizes knowledge in my Git course.
Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:
Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.