Chapter 3 Creating a Repository

Now that Git is configured, we can start using it. Although you probably wouldn’t normally use the Git Shell to create a repository, we are going to do so just so that we can get some degree of familiarity with this tool. It is also worthwhile noting that when things start to go astray, this is tool that will be used to sort out most problems. The syntax that is used resembles that of Linux and OSX rather than dos.

Let’s create a directory for our work and then move into that directory:

> mkdir test_one
> cd test_one

Then we tell Git to make test_one a repository, which is a place where Git can store different versions of our files:

> git init

You will note that it provides the following output:

# Initialized empty Git repository in C:/Users/Kevin Kotze/Documents/GitHub/test_one/.git/

Note that Git stores information about the project in this special sub-directory .git. If we ever delete it, we will lose the project’s history.

We can then check that everything has been configured correctly by asking Git to tell us the status of our project:

> git status
# On branch master
# Initial commit
# nothing to commit (create/copy files and use "git add" to track)

To check the current directory at any time we can use the pwd command:

> pwd 

We can also use the ls command to show the directory’s contents, which is currently empty:

> ls 

Please note that by changing the directory you are able to create “nested”" repositories. This is almost always a bad idea as Git repositories can interfere with each other if they are “nested” in the directory of another. In this case 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 remove a .git folder we would need to make sure that we in the correct directory. For example, if we want to remove test_one then we could run the ls -a command to make sure that test_one is there. Then run the following command if you are using a Mac or Linux machine:

> rm -rf test_one/.git

But be careful! Running this command has the potential to remove the entire git-history of a project that we may want to keep. In Windows you would probably be better off deleting the .git folder from within File Explorer after you have adjusted View to show all hidden files.