Creating a Repository

First, let's create a new directory under our home directory for our work and then change the current working directory to the newly created one:

cd ~
mkdir practice_git
cd practicegit

Then we tell Git to make a repository for our practice_git project. It is 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 practice_git repository, whether subdirectories are present from the beginning or added later. Also, note that the creation of the practice_git 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 practice_git called .git:

ls -a
Output:

.            ..           .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.

Next, we will change the default branch to be called main. This might be the default branch depending on your settings and version of git. See the setup episode for more information on this change.

Let' ask Git to tell us the status of our project:

git status
Output:

On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

We do not like the branch name "master". Let's change it to main

git checkout -b main

Let's again ask Git to tell us the status of our project:

git status
Output:

On branch main

Initial commit

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.

Last updated

Massachusetts Institute of Technology