How to create a GitHub repository?
Tags: git, gitcommit, github, gitpush
Published: 2019-05-12 19:19:18

---
title: How to create a GitHub repository?
published: true
tags: git,git-commit,github,git-push
canonical_url: https://medium.com/@nisevi/how-to-create-a-github-repository-3990a467661e
---

A simple guide to get you started with GitHub.

![](https://cdn-images-1.medium.com/max/1024/1*I_VX8P2sOhU83ijUtbRY5g.jpeg)

### Context

This blog will walk you through the different steps you need in order to have your GitHub account setup and ready for creating amazing things :)! We will set up the SSH key and also the GPG key for having signed commits. The operative system that I will be using is Linux, distribution [Ubuntu 16.04.3 LTS](https://www.ubuntu.com/download/desktop). If you are using Windows or MAC, you can follow this post as a guide but the respective commands for your operative system will be slightly different. You can post on the comments so I can help you. We will [install GIT](https://git-scm.com) and push our first signed commit.

### Creating a GitHub account

First, you just need to go [here](https://github.com):

![](https://cdn-images-1.medium.com/max/930/1*LLAC5eTXNfEAg8Qgkwnjdg.png)

Complete the form with the requested info, and you will have your account created immediately. It will look something like this:

![](https://cdn-images-1.medium.com/max/905/1*jCDIMrrMIFtDj47gRoZObA.png)

### Creating your first repository

Notice that you have different tabs in your profile view: `Overview`, `Repositories`, `Stars`, `Followers`, and `Following`. One of our interest is `Repositories`, click there :D!

It will appear a view with the new button in it, click it:

![](https://cdn-images-1.medium.com/max/686/1*mdlbWciucIkLoTMOTIXz5w.png)

After that you will be presented with the following form:

![](https://cdn-images-1.medium.com/max/687/1*dOI3QnLE1Q-ieEqt5-mvQw.png)

Notice that I completed the `Repository name`, I added a little `Description` and I clicked `Initialize this repository with a README`. This last step is important since we will be creating a repository with a file in it and it is different from when we create an empty repository (we will cover the empty repository later).

Regarding the name of the repository, I always use `downcase` only or combined with `_`.

Once you created the repository by hitting the button `Create repository` you will see something like this:

![](https://cdn-images-1.medium.com/max/911/1*bk2z061_F003nViAlanyEA.png)

A couple of things to notice here since we are gonna configure the SSH key and the GPG key, we will clone the repository with the Clone with SSH option.

### GIT installation

Now, if we want to work locally (meaning with our computer) with the repository we just created, we will need to install GIT.

Open a console `Ctrl+T` or go your programs an click the `Terminal` icon:

![](https://cdn-images-1.medium.com/max/566/1*6UqeDEt-szNQkXXm9YUU1A.png)

Once you are with the opened terminal, write the following command:

`sudo apt-get update`

This will update your local package index.

![](https://cdn-images-1.medium.com/max/619/1*2LqpZ8woEjd126WAw23gQg.png)

Now we will proceed to [install GIT](https://git-scm.com) with:

`sudo apt-get install git`

![](https://cdn-images-1.medium.com/max/976/1*d7PQw5c1emPxF0OkvamBog.png)

We also need to tell GIT who we are, and for that, we are going to set up our `name` and `email` with the following commands:

`git config --global user.name "Nicolas Sebastian Vidal"`

`git config --global user.email "nicolas.s.vidal@gmail.com"`

![](https://cdn-images-1.medium.com/max/880/1*ds2WQFBY1YmnZqt_GzLDhw.png)

Of course, where I have put my name it will go yours and the same with the email :).

### Configuring your SSH key

Before cloning our repository, and in order to be able to commit and push our changes to the GitHub repository, first, we need to generate our SSH key.

- Open a console `Ctrl+T` or go your programs an click the `Terminal` icon;
- Paste the text below, substituting in your GitHub email address.  
`ssh-keygen -t rsa -b 4096 -C "your\_email@example.com"`
This creates a new ssh key using the provided email as a label.  
`Generating a public/private rsa key pair.`
- When you’re prompted to "Enter a file in which to save the key", press `Enter`. This accepts the default file location.  
`Enter a file in which to save the key (/home/you/.ssh/id\_rsa):[Press enter]`
- At the prompt, type a secure passphrase. I encourage you to type a passphrase and not to leave it empty since it will give you more security.  
`Enter passphrase (empty for no passphrase): [Type a passphrase]`
`Enter same passphrase again: [Type passphrase again]`

![](https://cdn-images-1.medium.com/max/695/1*dvb6brlY9y_V3ig-nlH5cg.png)

- Start the ssh-agent in the background.
- Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace _id\_rsa_ in the command with the name of your private key file.

![](https://cdn-images-1.medium.com/max/613/1*aUYwWGNkEWO46D0uGPA1tw.png)

These last two steps are for not entering the passphrase [every time](https://stackoverflow.com/questions/10032461/git-keeps-asking-me-for-my-ssh-key-passphrase) you want to push your changes to your repository.

These mentioned steps can be found also [here](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/).

#### Adding the SSH key to your GitHub account

While being in your terminal, write the following command:

`cat ~/.ssh/id\_rsa`

This command will show you your SSH public key:

![](https://cdn-images-1.medium.com/max/1024/1*EuHWXhvBHmrdaILJxtpF6A.png)

Copy this key from `ssh-rsa` to your email `nicolas.s.vidal@gmail.com`.

Now we need to go to our GitHub profile, and click `Settings`:

![](https://cdn-images-1.medium.com/max/953/1*nlE2crDHwdIRcdxZ9tgWmA.png)

Once you are there click the option that says `SSH and GPG keys`, click `New SSH key` after that, it will appear a form where we will paste our `SSH key`, add also a title to identify the machine that it will be using the mentioned key:

![](https://cdn-images-1.medium.com/max/908/1*g05Qq5ly67Hfna27f2OopA.png)

Press `Add SSH key` and finally our key it will be configured to be used:

![](https://cdn-images-1.medium.com/max/649/1*eVly3rsNk7zmDbtzCAIWkg.png)

### Configuring your GPG key

If you want to have all your commits signed, follow these steps. Otherwise, you can completely avoid this.

Back in your terminal type the following command:

`gpg --gen-key`

Some options will appear, here the detail of each of them and the usual configuration that I use:

- `Please select what kind of key you want` I use the default option `RSA and RSA`;
- `What keysize do you want?(20148)` here you will see that I selected "2048", however, I only selected the default option because I'm using a virtual machine and it is kind of troublesome to generate the necessary entropy for getting all the needed bytes. I always go with 4096 as it is the recommended key size.
- `Key is valid for?(0)` for this example, I have chosen that the key should not expire but what I always change the GPG key every month :D!
- The next step will be to set up your `Real name`, `Email address` and `Comment`, this last one I use it to put my username :P!
- The last step, you will have to generate enough entropy for getting the needed bytes, so for this, you will have to start doing some work on your computer. you could start moving your mouse like crazy (that works for me), also typing on a text editor a lot of random characters. One thing, do it fast!.

![](https://cdn-images-1.medium.com/max/496/1*aHsr4B0cOJKy8-tT8845kw.png)

Once we have generated our GPG key we still need to add it to our GitHub account, the following steps need to follow:

- Use the `gpg --list-secret-keys --keyid-format LONG` command to list GPG keys for which you have both a public and private key. A private key is required for signing commits or tags:

![](https://cdn-images-1.medium.com/max/806/1*7NHBEU7WaVSK3uYSHP6C_A.png)

- From the list of GPG keys, copy the GPG key ID you’d like to use. In this example, the GPG key ID is 77384044A63D6CFF ;
- Configure Git on your machine for using this GPG key to sign your commits: `git config user.signingkey 77384044A63D6CFF`;
- Paste the text below, substituting in the GPG key ID you’d like to use. In this example, the GPG key ID is `77384044A63D6CFF`:  
`gpg --armor --export 77384044A63D6CFF`

![](https://cdn-images-1.medium.com/max/690/1*IIerOEvTL-gkIfRrEGfUJA.png)

- Copy your GPG key, beginning with `-----BEGIN PGP PUBLIC KEY BLOCK-----` and ending with `-----END PGP PUBLIC KEY BLOCK-----`;

#### Adding the GPG key to your GitHub account

Once again as we did with the `SSH` key, you need to go to your GitHub profile and click on the `Settings` option.

Once you are there, click the option that says `SSH and GPG keys` and click `New GPG key`, a form will appear where we will paste it:

![](https://cdn-images-1.medium.com/max/925/1*T9HjK9g610CkrkwFaJMcgw.png)

Press `Add GPG key` and finally our key it will be configured to be used:

![](https://cdn-images-1.medium.com/max/650/1*2CXhH7vivn8U6d-PYfB5cg.png)

The steps that I have mentioned to generate a GPG key can also be found [here](https://help.github.com/articles/generating-a-new-gpg-key/).

### Cloning our repository

Back in our terminal, we will go to `Documents` and there we will clone our GitHub repository:

![](https://cdn-images-1.medium.com/max/917/1*HAx0uyCxjB7i6uJtH9QWdQ.png)

We will clone our repository by using SSH, so our command line would look something like this:

`git clone git@github.com:nisevi/staticwebsite.git`

![](https://cdn-images-1.medium.com/max/807/1*JbPG84fmsM8_O1DpmPHUPg.png)

It will ask us if we want to continue since the authenticity of the host github.com can't be established, but! as we trust GitHub we will say `yes`.

After that, you will have the repository cloned within the `Documents` folder, and you will find the `README.md` file that we have selected for initializing our repository:

![](https://cdn-images-1.medium.com/max/498/1*enGtVdDUobQfmrVfCWvWpw.png)

### Pushing your first commit

In order to create a commit, first we need to generate some changes to the files that we have in our repository, otherwise, we won't have anything to commit.

In order to check the status of the files and see if any of them has changed, we will use the following command:

`git status`

![](https://cdn-images-1.medium.com/max/449/1*n9e75Hko8MrPWjzLH5Y4kA.png)

This is the actual content of the `README.md` file:

![](https://cdn-images-1.medium.com/max/475/1*05xZhy2t8TOyEV-MhrukZQ.png)

After the modification, we can see that our file was changed by typing the following command again:

`git status`

![](https://cdn-images-1.medium.com/max/685/1*L44WlVIx_FFyLCfQKZqZVA.png)

And we can take a look at the changes we have done with the following command:

`git diff`

![](https://cdn-images-1.medium.com/max/431/1*NmnEtFI72q8M24pdKt3bHw.png)

As we can see `Static website`. has been deleted, space has been added, and `Hello World.` was written.

Now, we will add this file to our commit by doing:

`git add README.md`

After running this command, we will be able to see that our changes have been added to the commit we want to create. We can check this by doing:

`git status`

![](https://cdn-images-1.medium.com/max/450/1*FvyzTNl8HIMVE_Vag1c0PA.png)

Our next step is to create a signed commit with a proper message about the changes we have done to the file. Please notice that here you will be asked to type the passphrase you used when creating your `GPG key` (if you have skipped that section you won't need to use the `-S` flag):

`git commit -S -m "Update README.md"`

- `-S` flag is for signing our commit;
- `-m` flag is for the message we want to write;

Once the commit has been created we will proceed to push our changes :D !!

Type the following command:

`git push origin master`

![](https://cdn-images-1.medium.com/max/555/1*O5yKS-IoB9z7NXPfZMcfwg.png)

Done!!! we have pushed our changes. If you want to see them, go back to your GitHub repository. You will see that the `README.md` file has changed and if you want to know if your commit has been signed click where it says `2 commits`:

![](https://cdn-images-1.medium.com/max/1005/1*8N1EWKRbgA-arRCtEWypgg.png)

In the following view, you will find the commit that we just did with the comment we have added; the green label that says Verified means that our `commit` has been signed :D!!!

![](https://cdn-images-1.medium.com/max/1017/1*b-hiw42dSgKnO7G2v7m9GQ.png)

Something to notice here is that I have already a signed commit that says `Initial commit`. This commit was created when we decided to initialize our repository with a `README;` for me is signed or `Verified` because I already have other `GPG key` and `SSH key` working on my laptop. What it matters is the commit that you just pushed :)!

This post ends here.

What you will find next are some alternatives to things that I have done in this tutorial. I hope you have enjoyed it!!

### Creating an empty repository

If you decided to create an empty repository, you will be presented with different options. Here, we will walk through the steps for having this repository cloned and working on your computer.

![](https://cdn-images-1.medium.com/max/1018/1*23glSrCbPISp-YyhOlFq3w.png)

Notice that I haven't selected the option `Initialize this repository with a README`. After you hit `Create repository` you will be presented with the following view:

![](https://cdn-images-1.medium.com/max/1017/1*fQqKJYZXFvQFH51tOYR1mw.png)

Please notice that I have selected `SSH` as we will clone the created repository by doing:

`git clone git@github.com:nisevi/staticwebsite.git`

![](https://cdn-images-1.medium.com/max/673/1*HsKEGz4aWUgg7DRoek-zQA.png)

As we can see the repository has been cloned but there is nothing inside the folder (except the `.git` configuration folder of the repository). At this point, you can just create any file and follow the steps we have described on `Pushing your first commit`.

### Cloning a repository by using HTTPS

Other option, instead of doing all the SSH and GPG configuration for pushing commits, will be to clone the repository with HTTPS:

![](https://cdn-images-1.medium.com/max/907/1*H5FUNT7W-egH_qduOCqKOg.png)

Back in your terminal, we will clone the repository by doing:

`git clone [https://github.com/nisevi/staticwebsite.git](https://github.com/nisevi/staticwebsite.git) https-staticwebsite`

The last part that I just added was only to give the folder a name, in this case `https-staticwebsite`. I have done this because I didn't want to have conflicts with the same repository that I cloned with `SSH`:

![](https://cdn-images-1.medium.com/max/889/1*dFAd_wkijiRI4syILsaQ0A.png)

If we take a look at the folders inside `Documents`, we will see:

![](https://cdn-images-1.medium.com/max/602/1*q2dXKpPjiG439Zq6K-eNfA.png)

We will get inside `https-staticwebsite` and do some changes to the `README.md` file and create a signed commit. But! as this is another folder with another Git configuration, we will have to setup our GPG key again by doing:

`git config user.signinkey 77384044A63D6CFF`

If you don't remember where this number `77384044A63D6CFF` comes from, you might take a look back to the section where we have configured the `GPG key`.

![](https://cdn-images-1.medium.com/max/847/1*_8Wh_cr1qIRIPE3kKaQWJw.png)

After we have created our signed commit we will push our changes:

`git push origin master`

![](https://cdn-images-1.medium.com/max/610/1*yKjbQAi0TgsFkosoyMb7PQ.png)

Notice that by using `HTTPS` you will always have to enter your `username` and `password`. In case you are using two-factor authentication instead of a `password`, you will need to enter a `token`.

### How to generate a GitHub token

Go to your profile and click `Settings`. After that, click `Developer settings` and select the option that says `Personal access tokens`, press `Generate new token` and give it rights only for repo, as displayed here:

![](https://cdn-images-1.medium.com/max/1002/1*tovwwChnol9YQcAYJiXRSw.png)

After you press `Generate token`, you will see the following:

![](https://cdn-images-1.medium.com/max/1008/1*T5u4HJyRyH7MMAaZVgwY1w.png)

Copy the token and save it in a safe place since this is the last time you will see it here. Once copied you can use it as password if you have activated two-factor authentication and want to push commits by using `HTTPS`.

* * *