How to create a Git repository
Need to create a new git repo?
Git is a distributed version control system that gives developers the ability to:
- Track changes made to files and directories
- Preserve a detailed history of commits
- Work independently in local branches
- Share code with others across a network
At the center of these capabilities is the Git repository. Once Git is installed, you can begin using its features by either:
- Creating a new repository, or
- Clone an existing repository from another user.
How to create a new Git repository
Follow these steps to create a new Git repository on your personal computer:
- Create a new folder for your project.
- Open the folder in Git BASH.
- Issue the git init command to create the new Git repo.
- Note the creation of the hidden .git folder in the project.
- Add files and folders to your project.
- Routinely stage files and create commits.
The aforementioned steps will set up your project and lead to your first commit. However, it is specifically the git init command that creates the Git repository.
Git init example
The following image shows the commands needed to accomplish several tasks in Git, including:
- Create a new Git repository with git init.
- Add a new files to the folder.
- Stage the file to the Git index with the git add command.
- Perform a commit with the git commit command.
After these commands are run, the new Git repo will contain a single commit that contains a single file named alpha.html.
How to create a repo in an existing project
A folder does not need to be empty to issue the git init command and create a new repository.
If a folder already contains files, here’s what you do:
- Simply issue the git init command in the root of the folder.
- Issue the git add . command to stage all files in the project.
- Perform a git commit.
After the first git commit operation executes, a snapshot of all of the project files in their current state will be stored in the newly created Git repo.
How to clone a remote repo
One of the most compelling features of Git is the ability to share code with others.
If you want to work on an existing repository that is hosted on a service such as GitHub or GitLab, you simply obtain the unique address of the repository and perform a clone.
For example, each GitHub repository contains a URL that uniquely identifies the repo.

The GitHub URL is used to clone a remote repository.
Copy the GitHub URL to your clipboard, and bring the remote repository down to your local machine with the git clone command.

The git clone command makes a remote repository accessible on your local machine.
Cameron McKenzie is an AWS Certified AI Practitioner, Machine Learning Engineer, Solutions Architect and author of many popular books in the software development and Cloud Computing space. His growing YouTube channel training devs in Java, Spring, AI and ML has well over 30,000 subscribers.