How to create a new repository in GitHub

GitHub is a platform where we can share our code with the rest of the programming world.

To do this, we must first make an account on GitHub and create a repository.

Repo – short for repository – is a storage location for our projects. From hello world to a fully-fledged documented project, we can push any project by first creating a repository on GitHub.

There is more than one way to create a repository in GitHub.

  1. Manually going through the steps on GitHub.com.
  2. Using the command line to create a new repository.

It is more common for programmers to do this using the Command Line Interface (CLI).

1. Creating a repo from GitHub.

To create a repo from GitHub, you need a verified account from GitHub before you can follow the below steps as illustrated.

  • Step 01 – Go to github.com. Create an account. On the top right-most corner, locate the drop-down menu shown below. From the drop-down menu, select new repository.
New repository drop-down menu.
New repository drop-down menu.
  • Step 02 – The following page will be displayed. Write a name for your repository.

We can describe our repository, including its purpose and its functionality.

If you want to make the repository private and not visible to others, select the private radio button.

The check buttons include a README file for your project, including the technologies and basics of importing your project to another machine.

You can check all or none of the options, depending on your requirements.

Create a new repo window
Create a new repo window
  • Step 03 – After filling in the name and description of your first repo, it will look like this.

Click on the Create Repository button to create your first repo.

Create a new repo
Create a new repo
  • Step 04 – After following the above steps, you are ready to use your first repository.

Now we can push any project on this repo.

Repository created
Repository created

2. Creating a repo from CLI

We created our first repo from a GitHub account. Now let’s learn how to do it by using the git command line from your local machine.

The following commands must be entered to create a repository using this method:

git init
git add somefilename
git commit -m "initial commit"
git remote add origin https://github.com/username/new_repo
git push -u origin master 

The git init commands initializes your repository. You do not want to create an empty repository, so you must add git add somefile in the procedure.

The commit commands save your changes to a local repository on GitHub. Every time we make any changes in the code, we commit the code.

The remote command states that this is a remote repository, and we have to add a path to it that shows its origin. The path is your repository URL shown in the below image.

Repo url
Repo url

And finally, we have to push our repo to the master branch. master is the actual project file we work on.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved