Git and GitHub — A complete beginners guide to getting started.

Kaneto Mbachu
Sprinthub Engineering
7 min readApr 29, 2020

New to git and want to know how to make use of it? I got you!

Feel free to skip the intro below if you have basic knowledge of git and want to go straight to the steps and commands.

Git? What’s that?

Git is a free and open-source distributed version control system that is designed to be fast and efficient. It is the most popular version control system in use today.

  • A version control system.

When developing software systems, we make changes to the source code continually.

Over time, it can become difficult to understand how the software got to its current state.

Version control systems are tools that help users track every change made to source code. Right from the people who altered it, the reason behind the alteration, the time it was altered, the particular file that was altered, how many lines of code that were altered (deleted, added or both).

While it keeps track of modifications made, it also keeps copies of the file that were altered, before they were altered, so that one can still make use of the file from before it was altered.

Version control systems help to preserve source code history.

  • A distributed model.

First of all !

There are two kinds of version control systems:

Distributed version control systems and Centralized version control system

Distributed version control systems store the source code on multiple computer systems making it possible for different members of a team to work independently, yet, together on the same project. Meaning they don’t have to be in the same space or connected to a single computer at the same time. They would each have access to the files and while they’re working and making changes, it is being recorded.

Centralized version control systems store the source code history on a single computer system. Every change that is made to the source code is sent to the central computer system that runs the version control system.

This model was popular in the past, but it has its problems. For example, central administration of the system means that if the source code is lost to a disaster, it may not be recoverable unless there were backups.

I’d say you shouldn’t bother about this one.

GITHUB / GITLAB / GITBUCKET / BITBUCKET / etc

An online platform, where projects are stored. It is linked to git so it can be transferred from one’s workstation / PC (the local repository) to one’s online git account (online repository) directly.

It is also a space to interact with other developers.

“ WHY SHOULD I USE GIT ? ”

There are a lot of reasons to use git. A few, however, are -

  • Productivity ! (work anywhere, anytime) — Because who doesn’t want that !?

Due to certain circumstances you’re unable to be at your place of work where your work files are (and your current project). Wherever you are (hopefully you’re with your PC or any available PC ) you’re able to pull the project from the online repo and get busy.

  • Never lose your progress ! — Always one step ahead of ill luck !

Say you unknowingly touched something you weren’t meant to, so your app is no longer doing what it’s supposed to, and you can’t locate the problem. If you’re the kind to push your work often, you have no problem. Simply pull your last uploaded work from your online repo and you’re good.

  • Easy collaboration ! — Can’t be in the same space as your team? Or you just can’t stand them.

Everyone on your team will have access to the online repo and will be able to work together, especially when not together. What I mean is you all do not have to be in the same space to work. Everyone can work remotely, saving time and meeting the set goals faster.

  • Save time ! — You can never have too much of that

Git offers several conveniences that make work faster. For example, undoing an embarrassing bug that was mistakenly introduced in a commit can be as simple as “git revert”.

  • More productivity ! — Because why not?

Git allows a single task to be carried out in parts by several team members. Thus, it can reduce the time spent on single work items.

Having access to a repository’s history allows you to quickly access information that would have been lost otherwise.

Also, testing out various ideas before committing to one is easier with git, due to its branching feature.

STEPS !!!

Step One ! -

Create an account !

Before you can start saving your files to GitHub or GitLab or other platforms, you should create an account.

Step Two ! -

Create a new repository ! — This is where your files will be stored. Enter a Name and hit create.

This is often referred to as an “online repository/repo”

Make it public or private !

Public — Anyone can see this repository but you choose who commits

Private — You choose who sees and commits

Step Three ! -

Create a repository on your PC ! The storage location on the PC is usually called a “ local repository/repo ”.

And here’s how to do that.

  • Choose a specific location on your PC for your git related activities.

Example: Home/Desktop/Dev/Local Repo.

NOTE:

You should note that using git requires you to make use of the CLI (Command Line Interface). So you should know a few of the commands. Just the basic ones so you’re able to move around your PC.

  • Install a command-line tool for your PC
  • It is often referred to as “Terminal”

Step Four ! -

Initialize a directory !

To let your PC know you’re going to be running git on that folder (Local Repo), create and go to the directory.

This is how to do it with your terminal

  • Open Terminal
  • Assuming the path to the folder you reserved for your git activities looks like this ”Home/Desktop/Dev/Local-Repo”. Here’s how to get there:

Focus on something that may look something like this => human@ani:~$

This is how it works !

Make sure you practice this to get accustomed to it !

- human@ani:~$ cd Desktop => cd == Change Directory

(This moves you to a different folder. Like when you double click on

a folder and you gain access to it.)

- human@ani:~$ cd Dev

(Moves you to the “Dev” folder, assuming the folder already exists)

- human@ani:~$ mkdir Local-Repo => mkdir == Make Directory

(This creates a folder. Now you have successfully created a “Local-Repo” folder)

- human@ani:~$ cd Local-Repo

(Moves you to the “Local-Repo” folder you just created)

Now you’re in the folder — Local-Repo — we’ll proceed with the fourth step

Still making use of our terminal,

human@ani:~$ git init

This should display a message like — “initialized empty git repository in Home/Desktop/Dev/Local-Repo/.git/ ”

Step Five ! -

Let git know who you are !

Set your username and email with -

human@ani:~$ git config — global user.name

human@ani:~$ git config — global user.email

Step Six ! -

Link your local repository to your online repository !

This is to enable you to save files to your online repo locally (saving files to the online repo is often called “pushing”).

NOTE: You should note all these terms so you don’t get lost in certain conversations and also so you sound like you know what’s going on… even if you don’t !

human@ani:~$ git remote add (remote name) (repo url)

remote name — Usually “origin”

repo url — Remote urls point to a git repository

  • So go to your online repository
  • Clone repository (copy repo url)

human@ani:~$ git remote add origin github.com/<username>/whatever-else-is-there

After that

human@ani:~$ git fetch (remote name)

This is done to verify if you’re currently in the repository and/or branch you expect to be in.

It displays the repository/branch currently on!

Done !

Step Seven ! -

Uploading your files !

Now the link has been set up, you may want to upload files to your online repository. This is how !

Note ! : Make sure the project you want to push(upload) is in the folder prepared for git activities. Using my example, make sure it’s in the Local-Repo folder.

=> Home/Desktop/Dev/Local-Repo/.git/

I recommend uploading them in folders — <folder-name> Work-Project

However if you’d like to upload in separate files, it can still be done. — <file> main.js

First of all !

Before uploading any file, be sure to ascertain the repository or branch you’re currently on, so as to not send it elsewhere. Like we did before using “git fetch origin”

human@ani:~$ git fetch origin

You’ll be shown the repository url and branch you’re currently on

If you’re on the wrong branch and would like to switch.

To switch branches run this !

human@ani:~$ git checkout <branch-name>

As we were !

Uploading the file(s)

human@ani:~$ git add <insert folder-name>

human@ani:~$ git commit -m “<insert message>”

human@ani:~$ git push

Your username and password will be requested, enter it !

Don’t worry about not being able to see your password, type it in anyways !

To verify if your upload is successful, run…

human@ani:~$ git status

Refresh the page on your online repo to see your newest upload.

Congratulations! You just made your first upload!

--

--