Creating a Repository
Overview
Teaching: 15 min
Exercises: 0 minQuestions
Where does Git store information?
Objectives
Create a local Git repository.
Describe the purpose of the
.git
directory.
Once Git is configured, we can start using it.
First, let’s a new directory in the home directory folder for our work (mkdir
command), and then change the current working directory to the newly created one (cd
command):
$ mkdir ~/planets
$ cd ~/planets
Then we tell Git to make planets
a repository
– a place where Git can store versions of our files:
$ git init
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
If we ever delete the .git
subdirectory,
we will lose the project’s history. It’s best to simply leave that directory alone.
In the setup episode, we set the default branch name to be main
for more information on this change.
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.
Key Points
git init
initializes a repository.Git stores all of its repository data in the
.git
directory.