Simple Steps to Create and Use Git and Github.

Sam Ayorinde
9 min readDec 13, 2019

--

I’m writing this article as a guide to those who are new to Git and Github likewise the “Experts”, your contributions and recommendations are welcome. I’m assuming you know the difference between Git and Github , well if you don’t let me quickly take you through it because to understand GitHub, you must first have an understanding of Git.

Git
Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows. In simple English, Git is a command-line tool that allows developers to easily collaborate, as they can download a new version of the software, make changes, and upload the newest revision. Every developer can see these new changes, download them, and contribute. You can visit its official page to learn more.

Github
GitHub is a global company that provides hosting for software development version control using Git. In other words, GitHub is a Git repository hosting service, but it adds many of its own features. See its official page to learn more.

How to Create A Github Account

Setting Up GitHub Account

Setting your GitHub account is easy and very simple. To set the account visit GitHub’s official website.

The login form will appear on the same page. Fill out the form with your details to create an account on GitHub.

In GitHub, you will be known by your username. So, it has to be unique. This error can also be seen in the below screenshot. Here, the username Sam is already taken by someone else so GitHub is raising the error and suggesting some unique usernames.

Avoid those duplicate entries and fill the form with your details. The green tick will symbolize correct and unique entries.

Once you press Sign up for GitHub button, you will be prompted to verify that you are not a robot.

Choosing a GitHub Account Plan

Once you have verified your identity, you can choose the GitHub plan you want to subscribe for.

For this tutorial and in general, as a beginner, GitHub Free plan is more than enough.

GitHub Pro is for those who would like to have more private repositories and people contributing to these repositories are high in number. These are generally organizations. You also get advanced tools if you choose GitHub Pro such as protected branches or graphs which denotes insights of your repositories like contributors, traffic, commits, etc. You can visit this link to read more about GitHub Pro plan.

Tailoring your experience is a survey that GitHub takes while you create your account. It will be the next step in the process.

Note: You might or might not get this survey window.

This survey is created to collect data about the users and the reason they have decided to create the account on GitHub. It contains three questions. You can skip this step if you want to.

As the next step, you would be asked to verify your email address. You can verify it by clicking the link GitHub sent you on your email.

GitHub Account Dashboard

Now that GitHub account is all set up, you can log in through your credentials on the GitHub’s website. Logging in will land on the GitHub dashboard which is personalized for everyone according to interests.

A GitHub dashboard will contain three sections.

Note: The header section contains important concepts and discussing them here will create complexity. Please ignore the section for now.

Congratulations, you just created a Github account.

Git & GitHub Put in 5 Simple Steps

To start, make a GitHub repository. Navigate to “New Repository” on GitHub. You should then be on a page that looks like this.

Note: It looks this way because I’m an existing user.

Click on + button, you will find a dropdown, click on New repository.

Simply give your repository a name, relative to whatever project you’re working on or going to be working on. Additionally, you can add a description if you’d like and do things like change the publicity of the repository.

At the bottom of the page, are a handful of other options to start your repository off with. This part can throw off beginners, as I will explain later on, but if you’d like to add a README, .gitignore, and/or license, go ahead.

Now that you have your GitHub repo, we can go over the 5 simple steps that will take place when working with Git and GitHub. These steps are as so:

  1. Initiate a local git repository on your computer.
  2. Add your remote repository.
  3. Start coding and add your files.
  4. Commit your code
  5. Push your local repo state to your GitHub repo.

Now that you have the steps, let’s break them down and explain how we go about doing them.

1. Initiate a local git repository on your computer

The idea behind using Git and GitHub is that you have a git repository online, which we created earlier on GitHub, and that we also have our own local Git repo on our local computer. To make a local Git repo, open the terminal/console in your projects folder and run the command

git init

This command creates a .git file in the directory that you are currently in. This .git file makes the directory it’s in a local git repository. So now that we have a local git repository, we can now connect it to our GitHub repository.

2. Add your remote repository

So we have our local repository, but how do we connect it to our GitHub repo we made earlier? This command allows us to connect our local repo to our GitHub repo.

git remote add origin [repo url]

Let’s break this command down to make sense out of it. We are working with the git remote functionality, which is why the first two arguments are git remote, so that’s simple enough. But what’s this add origin [repo url]?

We are adding a remote to our local repository named ‘origin’. The name ‘origin’ is not necessary either. If we wanted to, instead of ‘origin’, we could name the remote ‘purplecow’ or anything we want really. But the standard is to name it origin.

The last argument is the link to your repository, which looks a little like this: https://github.com/user/repo.git. You can find this link by clicking the Clone or download button, copy the link.

(Part 2)

If you added a README, or any other initial file when creating your GitHub, you NEED to follow this step. Otherwise, you may encounter some trouble. If you didn’t initialize with any files, you can skip this and go to Step 3.

The problem present is that your GitHub repo has a file that your local repository doesn’t have, which is whatever file you initialized with (README, .gitignore, etc). Your local repository is considered behind. To fix this, you now need to pull the files from your GitHub repo to your local repo. To do this we do:

git pull origin master

This will pull the README.md file or any files that GitHub started off with, into your local repo. It’s important that you do this now in the process. Otherwise, when you start committing changes, your repos will be considered ‘desynced’, and you’ll have to go thru a tedious process to get things right.

3. Start coding and add your files

Our GitHub repo and our local repo are all set up! Now it’s time to add files to the staging area. The staging area is basically just the “area” or list of updated files that are ‘appended’ to be committed. To ‘append’ a file, we use the ‘git add’ command. You can add individual files by doing something like this.

git add index.html style.js script.js

However, if we already have our project developed and fleshed out, and want the entire directory to be staged, we can do something like this.

git add *

This is going to add every file, in the current directory to the staging area, that Git detects has changed. But what if there are some files that you don’t want added? Perhaps you have a file with sensitive information that you don’t want Git having access to? This is where .gitignore comes in handy.

.gitignore is a file that allows you to blacklist other files to not be tracked. So when doing ‘git add’, you don’t accidentally add unwanted files.

To make a .gitignore file from the terminal, you may do this.

touch .gitignore

We then open the .gitignore file and filter unwanted files on separate lines. For example, on one line I may put node_modules to blacklist a folder named node_modules. On another line I may add .png, to blacklist all png files if I wanted to.

4. Commit your code

Almost done! We now need to commit our work. We added our files using git add and now need to save those changes to our local repository, as those are only in the staging area. To do this, run:

git commit -m "Initial Commit"

As mentioned, this command will commit any changes/additions we did using git add to our repo. The -m allows for us to put a message inside of our command, which we did after in quotation marks. Traditionally, on your first commit, you’ll have the message say “Initial Commit”.

5. Push your local repo state to your GitHub repo.

Now all that’s left is to update the state of our GitHub repository. We’ve been running all these commands and doing all these changes, but it’s only been affecting our local repo on our computer. So let’s run a command to update, or push, our GitHub repo.

git push origin master

Essentially what’s happening is, we’re pushing our master branch to our origin. Origin was one of the things we defined early on, being our GitHub repo’s URL.

So now, look at your GitHub repo page. If all went well, your push should be successful and you should see your files online! Simple enough, right?

The Five Big Steps to Get Started with Git and Github

These 5 steps can be converted to a list of these commands:

  1. git init
  2. git remote add origin (repo url)
  3. git add
  4. git commit -m “your message”
  5. git push origin master

But what do you do while you’re working on a project and you make changes? How do you keep your repo updated as you code? Well, just re-iterate steps 3–4.

For example, what if I fix a bug in my code, so I want to update my repo. I’d do something like this.

git add modifiedFile1.php modifiedFile2.txt

As taught earlier, I’d then have to commit those changes by doing running, git commit -m “Fixed a bug where taco was displayed as toast”. As you can see, I gave a detailed but short description as to what changes I made in the iteration.

Finally, I push those changes to my GitHub with git push origin master. And that’s pretty much all there is to Git and GitHub. There are also many array of commands and functionality that Git and GitHub hold, but you’ll slowly learn these as you need them, or by looking at the documentation.

Special Thanks to Nigeria Ethereum network, Awosika Israel for this opportunity to be part of the #500nigeriadevs4eth. Thanks to everyone who took their time to read! I hope this help!!! If you have any tips or suggestions, leave them down below.

--

--