Git Repository

Create Git Folder

Before we initialize a repository, we have to make a directory to work with our files. Let's try to create a new folder for our project:

$ mkdir my-project

$ cd my-project

mkdir - makes new directory
cd - changes the current working directory

Now that we are in the correct directory. We can start by initializing Git!

Note: If you already have a folder/directory you would like to use for Git: Navigate to it in command line, or open it in your file explorer, right-click and select "Git Bash here"

Initialize a Git Repository

Once you have navigated to your correct folder, you can initialize Git on that folder:

$ git init
Initialized empty Git repository in /Users/user/myproject/.git/

You just created your first Git Repository!

Note: Git now knows that it should watch the folder you initiated it on. Git creates a hidden folder to keep track of changes.


Adding new files

You just created your first local repo and it's empty. Say we want to add some files, or create new file using your favorite text editor then save it or move it to the folder you created.

For this example, I am going to make a simple HTML File like this:

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello world!</h1>
<p>This is the first file in my new Git Repo.</p>
</body>
</html>

and save it to our new folder as index.html

Let's go back to the terminal and list the files in our current working directory:

$ ls
index.html

ls will list the files in the directory. We can see that index.html is there. Then we check the Git status and see if it is a part of our repo:

$ git status
On branch master

No commits yet
Untracked files:
 (use "git add ..." to include in what will be committed)
  index.html

nothing added to commit but untracked files present (use "git add" to track)

Now Git is aware of the file, but has not added it to our repository!

Files in your Git repository folder can be in one of 2 states:

When you first add files to an empty repository, they are all untracked. To get Git to track them, you need to stage them, or add them to the staging environment.