Git the Absolute Bare Essentials with GitHub

For the longest time, I’ve been afraid of git. Until one day, I was forced to learn git to be able to collaborate in a team. There was no way around it, the most efficient way of collaborating code was through git. But once I started using git, I realized git was nothing to be afraid of. Yet, tutorials and guides were over filled with information about git. Somehow they made git complex and made me afraid of it. If I was given the bare essentials to do one solo project, I would’ve persevered on with the rest on my own. When learning, nothing is more mission critical then learning itself.

This guide is meant to be simple enough for someone to be able to learn git while they have just started to learn programming. This tutorial is using git in a project you’re doing yourself, so that you can start to save your code by using git instead of saving them onto your desktop locally. I realize this guide is cutting out a lot, which people who are first learning git won’t notice. I trust the people reading, will persevere onward after this tutorial. I hope that after reading this yourself, you’ll pass this onto anyone else who’s learning to code and saving locally.

What is git?

Git is a version control system, usually abbreviated VCS. In simplest terms, it literally means a way to save and track changes online. The way you save each change on a document over and over again to Google Drive.

Installing git

Use this link to install git on Mac OS.

Use this link to install git on Windows. (Use the Git Bash to follow along)

For Debian-based Linux like Ubuntu or Elementary OS

$ sudo apt-get install git-all

For everything else, use this.

GitHub Profile

Use this link and create a GitHub user profile if you haven’t done so yet.

Using git on a Solo Project

The idea of git is for you to have an online folder of code, which you can also save to. The way you save a folder to Google Drive. Except with git, you’ll be using the terminal to do so. Like how Google Drive is one platform of cloud storage vs Dropbox. GitHub is the same platform in that sense.

There is bit of terminology you have to get use too. An online folder of code on GitHub is called repository. Copying a folder from your repository to your computer is called cloning.

Let start by making our first repository on GitHub. On the top right corner you should press the ‘+’ icon and it should have a drop down. Click “New Repository” in the drop down.

You should have been greeted by the page below. Type “first-repository” in Repository Name (which is the title of your online folder or repository), keep everything else as is and then just hit Create Repository.

If you’ve been greeted by the image below, then you’re in you first repository! We now only care about copying the HTTPS link for your repository. If you hit the copy icon next to the link, it should copy to clipboard. This HTTPS link is what will let you copy your repository to your local computer or otherwise known as cloning.

Open terminal (Git Bash if you’re on Windows) and navigate to a directory you feel comfortable cloning your repository too. (If you’re not good with terminal, here is also a YouTube link for that too). I like to make a directory where called “Workspace” in my documents directory to dump all everything I work on. Once you’re in a place in your PATH, you’re comfortable cloning your directory into, type the following into your terminal and hit enter.

git clone (Paste HTTPS link from clipboard)

Once you hit enter, you may get a warning like mine. Nothing to worry about, but now you’ve cloned your directory onto your computer. You can navigate to that folder both GUI or terminal.

Here’s a little more terminology you have to learn before we continue. The repository on your local computer is called the Master while the online repository in your GitHub is called the Origin.

Now lets navigate into that directory, which is our master, through command line and create a new file inside our repository. Name it anything and type anything in that file. I created a text file called “hello”. You could have made a ruby file called ruby.rb. Once your satisfied, lets now have these changes saved into our origin repository in GitHub. The way we do this is by typing the following lines of code.

git add .
git commit -m "Created my first new file."
git push

When you hit enter you’ll be asked to log into your GitHub account. It’ll prompt your for your username and password. Once you’ve entered them, the origin repository should have updated the changes you’ve made to your master repository. If you refresh the page in your origin repository, you should see the file(s) you created. Every time you make changes to your master repository, enter the three commands (while writing what changes you made in-between the quotations on line 2 ) to make those changes to origin. This process is repeated over and over again, the way you hit the save button.

That’s it!

Great, how is this useful?

For now, it’s not as useful as it’s intended to be. What is useful for you right now is that you can clone your origin repository if you’ve accidentally deleted your master. If you’re working on this code on your desktop at home, you can download git and clone this to your laptop and vice versa. Git is extremely powerful and I hope that this has at least given you the bare essentials to get your feet wet.

Like what you read? Give Mohammed Chisti a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.