Skip to content

How to create a Git repository? How to connect it to GitHub?

  • by
  • 5 min read

In an article earlier today, we went through how to create a repository on GitHub on their website itself. However, seasoned GitHub veterans use something called Git to create new repositories or update existing ones.

In this article, we’re going to see how to create a repository using Git.

What is Git?

Git is a distributed version control system which is used to handle projects of any magnitude with relative ease and efficiency. It allows for multiple people to work on the same thing simultaneously and is a lifesaver for developers.

As you can guess, it is free and open-source. Git is available as a downloadable CLI/GUI client on Windows, Mac and Linux.

If you’ve been chipping away at the GitHub website and want something that’ll get the job done faster, you’re in the right place.

Also read: How to install Eclipse on Linux?

How to create a Git repository?

Step 1: First, we need to download and install Git. I’m downloading the Git Windows Client from the official Git website

Step 2: Once you’ve downloaded the setup file, follow along with the instructions. I recommend leaving all settings at default/recommended ones as I found that the default ones work fine in most cases. Wait for the install to finish.

Should you decide to play with the settings, make sure to give the setting a good read and double-check whatever it is that you’re doing.

Step 3: The git bash looks like a regular terminal window. Now, we need to navigate to the directory where we’ll be writing the code for our project. Once there, right-click inside the directory, and you should see two new options

  • Git GUI here
  • Git Bash here

As you can guess, the GUI opens up a window which takes you through the various steps while Bash opens up a terminal.

Let’s go ahead with Bash for now.

Step 4: The first step when you create a new project for Git should be initialising the repository. You can do this by typing

git init

Step 5: Now, it’s time to start working on your project. Go ahead and add some code, create files, folders anything. I recommend starting with a readme file which describes the project.

Step 6: When you’re done adding files and want to update them in the repo, type in

git add [filename]

Alternatively, you can type in Git add . to add all files in the directory.

Step 7: Finally, type in Git commit to save changes to the repository. When you type in the command, Git will take you to a Vim like a screen where you’ll have to type in your initial commit message.

Press ‘I’ to go into insert mode and type in your git message. Once you’re done, press the ESC key and type in


and press enter. This will commit your changes to the repository.

If you’re not very much into Vim though, you can type

git commit -m ‘your message’

for a simple commit statement

How to connect the Git repository to GitHub?

Right now what we’re working with is just a local repository. Now it works just fine, however, to be able to push it to GitHub, we’re going to have to do some extra work.

Step 1: Create a new repository on GitHub. Check this article for reference.

Here’s a quick test repo

Step 2: As soon as you create your new repository, GitHub will automatically give you the steps needed to get up and running with Git.

To connect the two repos, we’re going to copy and paste the following statement into our Git Bash:

git remote add origin

This will, of course, be different for you.

Step 3: To push your repo online, simply type in the next command:

git push -u origin master

A window will pop up asking for your GitHub credentials. Go ahead and log in.

Punch in those credentials

After logging in, if all goes well, you’ll see that all your files have been pushed to the online repo.

All files are up and running

You can also go ahead and check this on the GitHub repo page. The files will reflect there as well

Also read:9 reasons why developers tend to choose Linux over Windows

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: