Jose Robledo
04 March 2025
We will help Alfredo with his new project, create a repository with all his 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:
recipes
a repository:It is important to note that git init
will create a
repository that can include subdirectories and their files. Also, note
that the creation of the recipes
directory and its
initialization as a repository are completely separate
processes.
git init
, a hidden folder
was created in the current directory. It is always called
.git
and you can see it by listing the files in the current
directory with an additional flag to show all files and
folders (including hidden ones):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.
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.
Output:
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
Along with tracking information about recipes (the project we have
already created), Alfredo would also like to track information about
desserts specifically. Alfredo creates a desserts
project
inside his recipes
project with the following sequence of
commands:
$ cd ~/Desktop # return to Desktop directory
$ cd recipes # go into recipes directory, which is already a Git repository
$ ls -a # ensure the .git subdirectory is still present in the recipes directory
$ mkdir desserts # make a sub-directory recipes/desserts
$ cd desserts # go into desserts subdirectory
$ git init # make the desserts subdirectory a Git repository
$ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository
Is the git init
command, run inside the
desserts
subdirectory, required for tracking files stored
in the desserts
subdirectory?
Git repositories can interfere with each other if they are “nested”:
the outer repository will try to version-control the inner repository.
Therefore, it’s best to create each new Git repository in a
separate directory. To be sure that there is no conflicting
repository in the directory, check the output of
git status
. If it looks like the following, you are good to
go to create a new repository as shown above:
Alfredo would like now to go back to a single git repository. How can
Alfredo undo his last git init
in the desserts
subdirectory?
REMIMNDER: To delete if
git init
initializes a
repository..git
directory.Content