Learn Version Control with Git

git init

Now that we have a basic understanding of what git is, let's start by creating our very first git project. Now using what we learned previously

  • navigate to your desktop using cd

  • create a folder using mkdir and call that project: project-1

  • then create a file inside that folder using touch: project-1.txt

  • Now using nano, write the following sentence: This is my first project

  • Then verify by printing the sentence using cat, the terminal should print: This is my first project

Creating a git project

In order to convert our project into a git project, we need to make use of the git init command. Make sure you're inside your project-1 folder, and do the following in your terminal:

git init

>> Initialized empty Git repository in /Users/jadslim/Desktop/project-1/.git/ Notice the output. git init sets up the tools necessary to begin tracking your project. If you see the message above, then your git project has been created.

What's exactly happening when you run **git init**?

When you run theĀ git initcommand, git will create a special file called .git inside the root directory of your project. if you remember from previous lectures, a . at the beginning of a file or folder, makes it hidden.

Inside your project directory

ls -a

>> . .. .git project-1.txt you can clearly see the project-1.txt file and the .git file. The .git directory is the repository. This is where all the snapshots of your changes will be recorded.

What's inside the git directory?

let's navigate inside the git repository:

cd .git
>> HEAD		   config		    hooks		objects
   branches	 description	info		refs
  • The HEAD file: The head file determines the current working branch that we are working with.
cat HEAD
>> ref: refs/heads/master

The output of HEAD shows us that the current active branch refers to master. We will explore exactly what that means in future lectures.

  • The config file: This file stores the configuration settings of your project. For example, you can set a username or email address for your git repository, and it will be stored in that file

  • The description file: Git generates a file named description, this contains the name of the repository. It's not very important at the moment.

  • The hooks directory**:** This directory allows you to set up scripts that can be used to tap into Git's lifecycle events.

  • The info directory: This folder contains an exclude file to ignore specific git patterns.

  • The objects directory: This directory will store all the snapshot commits of your project.

  • The refs directory: This directory contains the pointers to commits.

The information above isn't critical to the understanding of this course.

Feedback Summary
3 students





Written Reviews
There are no written reviews yet.