Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
Git is a popular version control system used by developers to manage their code. One of the first steps in using Git is to create a new repository. In this lab, you will learn how to initialize a new Git repository.
Create a New Repository
We have learned how to clone an existing Git repository. Now, let's create a new Git repository from scratch.
Open your terminal or command prompt and follow the steps below to create a new Git repository:
cd ~/project
git init my_repo
This will create a new directory named my_repo in your current working directory and initialize a new Git repository inside it.
Let's see what inside the my_repo directory:
ls -a my_repo
You should see the following files and directories:
. .. .git
The . and .. directories are special directories that represent the current directory and the parent directory, respectively.
The .git directory is where Git stores all the configuration files and version history for the repository.
Try running the following command to see the files and directories inside the .git directory:
ls -a my_repo/.git
You should see the following files and directories:
. .. branches config description HEAD hooks info objects ref
- The
branchesdirectory contains references to the branches in the repository. - The
configfile contains the repository-specific configuration settings. - The
descriptionfile contains a short description of the repository. - The
HEADfile contains a reference to the currently checked out branch. - The
hooksdirectory contains scripts that can be triggered by Git events. - The
infodirectory contains global information files. - The
objectsdirectory contains all the objects in the repository. - The
refdirectory contains references to the commits in the repository.
We don't need to worry about the contents of the .git directory for now. Just remember that it's where Git stores all the information about the repository.
Summary
Creating a new Git repository is a simple process that involves using the git init command. By following the steps outlined in this lab, you can easily create a new Git repository and start managing your code with Git.