#MyGitJourney – Creating and Exploring a new Git Repository

The time has come to create my first Git repository. Remember, I’m still taking baby steps here, so everything I do is going to be on my local machine right now. In this post, I’m going to create an empty Git repository on my local machine, and then dive into what gets created for me automatically.

I’m going to start out by opening the Git Bash shell. Remember, with Git for Windows I can use either the Git CMD prompt or the Git Bash shell. I like the color coding in the Bash shell (plus it makes me yearn for my Unix days in college), so I’ll stick with it for now. I changed to the C drive, then created the C:\Repos\mylab folder. This will be where I create my first repository

Once I’m in that folder, to create a new Git repository, I run the git init command. This should create a new basic repository named .git under the mylab directory.

Sweet, it worked! From the output I can see that it was created successfully, and if I look in the current mylab folder, I can see a .git subdirectory. Notice also how the prompt label has changed. By adding the word (master), it is visually showing me I am in a repository, and what branch.

I’m curious what’s in the repository that is created for me automatically. I can change directories into the .git directory (again notice how the prompt label changes), and see the following:

Cool! Git provides a skeleton repository of “stuff” for us.

Let’s break down what we see here:

  • config – This is the local configuration file where configuration settings specific to this repository are stored.
  • description – This is intended to be a human-readable description of the repository. It is primarily used by web browsers and hooks (which are apparently a Git thing. I’m sure I’ll find out more later).
  • HEAD – This is a pointer that contains a reference to the current item you are pointed to in Git, which is usually the current commit on the current branch.
  • hooks – a hook is a script that runs before/after an operation in git. This directory contains sample code for hooks.
  • info – This directory is used for multiple internal purposes, such as storing reference information for services. It also contains a file named exclude, that is another way to tell Git to ignore (not track) certain files. However, the primary way to do this is to use a .gitignore file. (I sense a blog post about this in the future)
  • objects – This directory is where Git stores the internal objects it creates with the contents of commits, files, directories, etc…
  • refs – This directory holds the master set of references for anything that points to a particular SHA1 value, such as a branch, tag, etc… (ooooh, I suppose at some point I need to talk about SHA1 and Git…)

If I do a cat description, I see the following:

This phase is the content of the description file. If I open this file, I can see that the file contains the above phrase. To change the description of my repository, I can add the description to this file. I’m going to change the description to be “Mickey’s First Repository“. Now if I run cat description again, I can see the repository description is changed, as expected.

Up next, I am going to create some new files and add them to staging!