A beginner’s guide to Github

Hrishikesh Paul
5 min readSep 13, 2019

This guide is for those who already have git installed on their systems. If you do not have git installed, a simple search on google will probably yield a handful of good tutorials. So if you want to go ahead, please install git!

So it’s that time of the semester (or you’re just curious to learn something new), and assignment submissions are through github. Quite a few people seem to be new to github, so here I have tried to kinda ease the pain of learning something so vast by explaining some git functions that could get you started off. I’m going to be writing everything on my command line, so for those of y’all who are afraid of the terminal, shhh (it’s simple!).

Since I will be using the terminal, I’d suggest Windows users to use gitbash (I believe it comes along with your git installation), because it makes life much easier. For Linux users the terminal is really powerful, so we are good to go.

Cloning

This is basically ‘downloading’ the repository from github to your system. So navigate to your folder and type the following command in your terminal/shell,

git clone <repository_url>

For this example, I’ll be cloning a repository that I have on my account. So my command will look something like,

git clone https://github.iu.edu/hrpaul/Github-Tutorial.git

You should find the link either on the address bar on top of your browser or in github, you can copy the link as shown in the image below,

Clone your repo

At times, it may ask you for your username and password, but that should be just fine. After you’ve cloned it, you’ll see it in your file manager. Pretty simple, right? Let’s move on!

Add & Commit

So let’s say you have a file(in my case README.md), and you have made some changes to it. And now you want to ‘update’ the file on your github repository. This is done in two steps. First is called staging. This helps in ‘reviewing’ your changes before you actually commit. (Kinda like that last part of engagement(staging), where you decide to walk off before getting married(committing), jk).

So let’s go through this one by one. First step is to make some changes to your file. In my case it’s the README.md. The changes that I have made is shown below,

Making edits to README.md

Next step is staging. Therefore, your command will be(assuming you are in the same folder as your file),

git add <name_of_file>

In my case, since I have edited just the README.md file, my command will look like,

git add README.md

And lastly for the commit,

git commit -m ‘write some good message here’

So the flag -m is for writing a small note about what your commit does. Just a few words or a sentence is usually a good practice because sometimes a project/file can have a lot of commits, so you kind of wanna add a note as to what each commit did.

Remember, you cannot commit without adding (staging). (Cannot plan a marriage without an engagement (??) I’ll stop, fosho)

Push

Ah, so now it’s time for you to put your local changes onto your repository on github. So your command will be,

git push origin master

Okay, so here I’m just considering pushing it to the master branch(yes, branching is a little complicated topic, so I won’t be talking about it here). The word origin is called your remote, which basically contains the URL of your repository on github. Don’t stress too much about handling remotes and branches as you pretty much won’t need them at this basic level.

So now your repository has your updated code! In my case, I can see my updates as shown in the image below,

Updated github repo

Remember, you can only push if your code is locally committed.

Pull

I feel that this ‘basic’ guide should also talk about how to update your local repository if your github repository is updated. Even though pulls have a lot of rules and can cause problems, I’ll briefly touch upon this.

So you use pull, when you have something on github and you want to get it onto your local system. Remember, this is NOT the same as cloning. Cloning basically gets the FULL repository onto your system. But pull will only cause specific files in your local system to update to the newest value. Let me explain this with an example.

Let’s say that my README.md file was updated by a friend of mine and is now on my github repository. The image below shows the changes that has been made to the file,

So if you want to get those changes onto your local system, type the following command (while being in the same folder as your file on your terminal/ shell),

git pull

This two word command should do the job. Now if you open your file, you should have the updated changes from your github repository. Image below shows how my README.md file looks,

Okay, having spoken about pull, there is one thing you have to remember, you can only pull if there are NO changes made to your file(s). If you have made changes to your file, and would like to pull, you would want to either discard your changes or commit your changes.

Conclusion

So the basic flow of operation should be,

Add -> Commit -> Push

Discard Changes/ Commit -> Pull

There could be conflicts(when you have edited the same lines of code as your friend), but at a beginner level I believe these commands are good enough of a start.

Remember, I’ve used the word ‘locally’ everywhere. But it doesn’t really have to be on your system. You can also follow the same steps if you have access to a cloud computer.

Happy coding!

--

--

Hrishikesh Paul

Hi there, nice to meet you! Welcome to my medium page! I’m a coder who can design and I love eating sushi!