Once Git is configured, we can start using it.
We will continue with the story of Wolfman and Dracula who are investigating if it is possible to send a planetary lander to Mars.
Werewolf vs dracula
by b-maze / Deviant Art.
Mars by European Space Agency /
CC-BY-SA 3.0 IGO.
Pluto /
Courtesy NASA/JPL-Caltech.
Mummy
© Gilad Fried / The Noun Project /
CC BY 3.0.
Moon
© Luc Viatour / https://lucnix.be /
CC BY-SA 3.0.
First, let’s create a directory in our home folder for our work and then move into that directory:
$ cd ~/
$ mkdir planets
$ cd planets
Then we tell Git to make planets
a [repository]({{ page.root }}{% link reference.md %}#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
includes subdirectories and their files—there is no need to create
separate repositories nested within the planets
repository, whether
subdirectories are present from the beginning or added later. Also, note
that the creation of the planets
directory and its initialization as a
repository are completely separate processes.
If we use ls
to show the directory’s contents,
it appears that nothing has changed:
$ ls
But if we add the -a
flag to show everything,
we can see that Git has created a hidden directory within planets
called .git
:
$ ls -a
. .. .git
Git uses this special subdirectory to store all the information about the project,
including all files and sub-directories located within the project’s directory.
If we ever delete the .git
subdirectory,
we will lose the project’s history.
We can check that everything is set up correctly by asking Git to tell us the status of our project:
$ git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
If you are using a different version of git
, the exact
wording of the output might be slightly different.