Initializing Git Repository

Learn how to initialize a “Git repository” in your project.

We'll cover the following

To initialize a Git repository, run git init from within the root folder of the source that you want to manage.

1   mkdir lgthw_git_basics
2   cd lgthw_git_basics
3   git init
Terminal 1
Terminal

Click to Connect...

This locally initializes a database in the folder .git. Your repository is entirely stored within this .git folder. To work with this repository, you don’t need to worry about any other files.

There are config files for Git, but these are global to the host. You can ignore them for now.

Have a look at the files within your .git folder by typing in:

4   cd .git
5   ls

It’s not part of the scope of this course to go into detail about all the Git internals files seen here. You will cover some of them as you dive into the course though.

What is worth being aware of here are:

  • The HEAD file
  • The config file

The HEAD file is key: it points to the current branch or commit ID you are currently on within your Git repository.

If you look at the file, you will see its contents contain the string:

refs/heads/master

This is an internal representation of the default master branch. Let’s take a look at the HEAD file.

6   cat HEAD
Terminal 1
Terminal

Click to Connect...

The file’s contents link the HEAD of the repository to the refs/heads/master file.

Git configuration#

The config file stores information about your repository’s local configuration. For example, the branches and remote repositories your repository is aware of. Again, it’s a plain text file with a basic config structure:

7   cat config
Terminal 1
Terminal

Click to Connect...

Again, don’t be concerned with understanding what it all means yet. Just be aware of its existence.

Introduction: Git Basics
Looking at Repository's History
Mark as Completed
Report an Issue