As I’ve worked for several years with documents, I understand the need to define the revision index of a document, when it needs to be changed. So, when I first read about version control (and Git and GitHub), I could immediately understood its importance, even if this is not properly the same thing as a document revision.
One good thing to do when learning to program is to take confidence in version control, especially for two reasons:
When a project needs to be revised, version control gives you the possibility to see all the precedent versions.
A system version control, like GitHub for example, gives you the possibility to work locally on your project and store the versions even online, so that you can show your projects to the world, share knowledge, etc…
So, let’s see how to create a repository on GitHub.
Create a GitHub account and install Git on your PC
The first step is to create a GitHub account. You can do it here.
After that, you have to install Git on your PC. You can download it here.
Now, open the terminal and set up your email by typing the following code:
git config --global user.email YOUR_EMAIL
Of course, YOUR_EMAIL
is your complete email address. Make sure you use the same email address for setting up Git and for signing up on GitHub.
Now, set up your Git name by typing this code:
git config --global user.name YOUR_NAME
Where YOUR_NAME
can be your complete name or a nickname: you decide.
Git is now set up and configured. The next step is the creation of an SSH key.
Create an SSH key
An SSH key is an item to protect you when accessing a remote PC that guarantees you protection from cyber attacks.
So, let’s see how to set an SSH key.
Open another terminal and type this code:
ssh-keygen -t ed25519 -C "YOUR_EMAIL"
In the above code use the email you’ve used in the previous steps, and use the “”
properly as typed.
Now, you will see a lot of code after you have typed this command, as this command generates a private key and a public key.
Before going on, to check that everything works fine type this command:
eval `ssh-agent`
If you get something like:
Agent pid 125746
it means that everything works fine and we can go on.
Now, you can get the public SSH key. If you see the code generated after you typed the ssh-keygen -t ed25519 -C "YOUR_EMAIL"
command before you can easily find a line which is something like:
Your public key has been saved in /home/YOUR_PC/.ssh/id_ed25519.pub
Which defines the folder where your keys are stored. Anyway, as said before, we need just the public key. To get it, we can type in the terminal (this is for Linux users. If you are not a Linux user, you can navigate to the file and open it):
cat ~/.ssh/id_ed25519.pub
and we get:
ssh-ed25519 NUMBERS_AND_LETTERS
Now, copy this result: we’ll paste it on GitHub.
Go to GitHub and log in to your account. Go to settings > SSH and GPG key and click on New SSH key. Here's what you'll see:
(Adding SSH key on GitHub. Image by the Federico Trotta.)
Give it a title and copy the key (ssh-ed25519 NUMBERS_AND_LETTERS
) under the key tab.
Now, we can create our first local repository and connect it to a remote repository on GitHub.
Your first GitHub repository
Now, let’s create our remote repository on GitHub. Let’s go on New repository and let’s give it a name. Let’s say we call it example and let’s set it to be public (so it can be seen by anyone). This is what you see:
(Your first repository. Image by the Federico Trotta.)
The only thing you have to do now is copy the last three lines of code:
git remote add origin git@github.com:t-YOURNAME/example.git
git branch -M main
git push -u origin main
Get those lines copied: we will paste them into the terminal in a moment.
Now, on your PC create a local folder where the files will be. We’ll call the folder example so that the local and remote repositories have the same name.
Now, we are going to use Git.
On the terminal type the following:
git init
This will make your local folder a repository. Then, you can see its status by typing:
git status
And you will see the status of the repository. Since it is a new one, the terminal will tell you that there is no commit. Moreover, the terminal will tell you all the files that are in the folder.
Let’s say you have a file my_file.p
y which is the file you want to stay in the repository (the local one, and you want it to be in the remote one in GitHub). You can choose the files to commit or to commit all. In this case, we just have one so we type:
git add my_file.py
(In case you want to commit all the files, type: git add
.)
Now, commit it:
git commit -m 'initial version'
This means that the name of the revision is initial version, but you can call it as you want.
Finally, paste the lines copied on GitHub. Let’s catch them again:
git remote add origin git@github.com:t-YOURNAME/example.git
git branch -M main
git push -u origin main
And we are done!
If you now see in your GitHub repository (called example) you will see the my_example.py file.
Conclusions
In this article, we've shown how to create a new repository on GitHub.
I hope you find it useful!
Hi, my name is Federico and I am a freelance Technical Writer:
Do you want to start a documentation project, collaborating with me? Contact me!
Do you want to know more about my work? You can start with my case studies and my portfolio.
The article "How To Create a Repository in GitHub" was first created for my blog here.
Hi, I am Federico Trotta and I'm a freelance Technical Writer.
Do you want to collaborate with me? Hire me.
Top comments (0)