How to create a Git repository

Why create a new git repo?

Git is a powerful, distributed version control tool that allows users to:

  • Track changes to files and folders
  • Maintain an extended history of commits
  • Perform isolated development in local branches
  • Share code with any other networked users

The core Git artifact that enables these features is the repository. After you install Git, to take advantage of these features, you must either:

  • Create a new Git repository of your own
  • 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:

  1. Create a new folder for your project
  2. Open the folder in Git BASH
  3. Issue the git init command to create the new Git repo
  4. Note the creation of the hidden .git folder in the project
  5. Add files and folders to your project
  6. 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:

  • 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.

start new git repo init create

Use the git init command to create a new Git repo.

Create a Git repo in an existing project

A folder does not need to be empty in order to issue the git init command and create a new repository.

If a folder already contains files:

  • 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 is performed, a snapshot of all of the project files in their current state will be stored in the newly created Git repo.

Clone a remote repository

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 like 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.

Star a new git repo by cloning

The GitHub URL is used to clone a remote repository.

With the GitHub URL copied to your clipboard, the remote repository can be brought down to your local machine with the git clone command.

start a new git repository with a clone

The git clone command will make a remote repository accessible on your local machine.






App Architecture
Software Quality
Cloud Computing