Create a repository
git init
initialises a repository.
- Git stores all of its repository data in the
.git
directory.
Once Git is configured, we can start using it.
We will create a repository with all our favourite recipes.
First, let’s create a new directory in the Desktop folder for our work and then change the current working directory to the newly created one:
cd ~/Desktop
mkdir recipes
cd recipes
Then we tell Git to make recipes a repository – a place where Git can store versions of our files:
git init
It is important to note that git init
will create a repository that can include subdirectories and their files—there is no need to create separate repositories nested within the recipes repository, whether subdirectories are present from the beginning or added later. Also, note that the creation of the recipes directory and its initialisation as a repository are completely separate processes.
If we use ls -a
to show everything, we can see that Git has created a hidden directory within recipes called .git:
. .. .git
Git uses this special subdirectory to store all the information about the project, including the tracked files and sub-directories located within the project’s directory. If we ever delete the .git subdirectory, we will lose the project’s history.
Nested subdirectories
You do not need to initialise a repository in a subdirectory of a directory that is already a repository – in fact, it is best not to!
Check status
We can now start using one of the most important git commands, which is particularly helpful to beginners. git status
tells us the status of our project, and better, a list of changes in the project and options on what to do with those changes. We can use it as often as we want, whenever we want to understand what is going on.
We can now start using one of the most important git
commands, which is particularly helpful to beginners. git status
tells us the status of our project, and better, a list of changes in the project and options on what to do with those changes. We can use it as often as we want, whenever we want to understand what is going on.
git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)