My Profile Photo

Trevor Jones

My musings - interesting to me, hopefully will be for you

Github for Absolute Beginners

On to Github.

Ok, now you’ve gotten the hang of the terminal/command prompt tutorial and Git. Next step is Github. Remember, Github is NOT Git. Github is like a social hub of programmers. You can create projects in your account which others can then view or even add to. You can follow users to see their latest projects or updates to current projects. Overall, it’s an open source community meaning anyone can look at or add to (with permission) someone else’s code. This may sound crazy, but again, you can only add to someone’s code once you have their permission. Generally, they’ll look over your code to make sure it will actually improve their current code and not break it. And if you’re working on a top secret project, you can make it private.

So going back to our novel example, multiple authors could be working on this book. If you’re in charge of chapters 1-3, you can add them to Github for the other authors to see. Then if any of your author friends think they can improve on those chapters, they can send you a request to add their changed content. Then you can decide if it indeed does improve your chapters and accept those changes. You can also look at their chapters and send in your own requests. All the while, Git tracks the changes for you, giving you controlled versions of your book. There’s lots more you can do, but if you understand that, you understand much of Github.

And now you should understand why Github is so powerful for companies. If they’re working on a project and have multiple developers, everyone can easily contribute and you can easily keep track of the growth of the project (and BTW, you can keep things private if you don’t want to give away your code, but it’ll cost a little money).

Now let’s use Github for our novel project. If you haven’t already, set up a Github account (using best practices for picking a username. Make it professional and avoid numbers or funny symbols). Done? Now we can set up what’s called an SSH key. This tags your computer to Github so Github knows it’s a trusted computer. This is just handy because otherwise, every time you commit to Github, it would ask you your username and password. Having this key means it won’t have to ask you every time because it knows your computer.

Follow these instructions closely to get that set up. Open your terminal/command prompt and type this in one at a time (always pressing ‘Enter’ at the end of each line and substituting appropriately).

	git config --global color.ui true
	git config --global "Github username"
	git config --global "Github  email"
	ssh-keygen -t rsa -C "Github email"    

It’ll spit some stuff out which you don’t need to worry about. Next, copy/past this command into your terminal/command prompt and hit ‘Enter’. cat ~/.ssh/

Again, all this is doing is generating that specific key for you to install into Github to register your computer. Now it should spit out a bunch of letters followed by your email at the end. Highlight all these letters until you get to the end of your email and copy it. Then go to this link to paste it in. Click “Add SSH Key” on this page. It will look like this:

SSH key

Enter a title like “My Computer”, then paste the key in. Save it and you’re done!

You can check to see if it worked by typing into your terminal/command prompt ssh -T

Somewhere at the end of the code it spits out, you should see something like:

Hi ‘username’! You’ve successfully authenticated, but Github does not provide shell access.

And you’re good to go here.

So again, all we’ve done is ‘register’ your computer to Github so it knows to accept requests to your account from your computer. If you decide to use someone else’s computer to make a request, you’ll most likely be asked your Github username and password. This is to protect you so no one else can add changes to your projects without your permission.

With your account you can now make gists and repositories. Gists are normally single files that aren’t part of any projects, sometimes like example files. You can check out what I mean by looking at mine. Those were just practice for me running Ruby programs.

You can easily add gists by clicking on gist towards the top of your page (obviously if you’re not in your Github account, go ahead and get there).

Here you’ll see where you can add a title, a description, and then your code. If you have any little samples of code to put in here, go ahead!

Gists are great for those small bits of code you have, but it is NOT where you want to put full fledged projects. For those, we want repositories.

So let’s set one up! I do suggest you make an example repository with me, but no worries, you can delete it later if you don’t want other people to see your practice runs. Also, it’s common to call these repos so I’ll be calling them that from now on. If you’re still in the gists section, go to the upper right and click on the cat face, then click your username in the top right. To the right of your photo you should see a ‘Repositories’ section you can click on. Click the bright green new button along the right hand side.

In this section we need to create a name and a description. You can name it anything you want, but normally you want it to be descriptive so others can get an idea of what the project is by looking at its title. For our example, we can just use ‘Novel’. It’s also a good idea to name this repo the same name as the one on our computer (which is the folder we are holding our chapter files in). Then write your own description and click ‘Create repository’. For this, don’t worry about adding a README. You can on future projects and it is helpful as it describes what your project is or how someone can use it. But this is practice and we’re going to delete it later, so there’s no use in creating a README.

For now, stay on the page where it’s asking about your repo:

Create repository

Great! So what we want to do now is put the ‘Novel’ folder on our computer to this repo on Github. Your Novel is sitting in that ‘Novel’ folder, which is actually what you call your ‘local repository’. You can find it locally on your computer. We want it to go remotely on Github - a remote repo is one up on Github (a place where others can access, not just locally on your computer).

To do this, we are going to “Push an existing repository from the command line”. Meaning we are going to load our local ‘Novel’ repo into our newly created remote ‘Novel’ repo.

Let’s push it! ‘Push’ just means load it up from our local repo to our remote one. First, we need to tell Git that we have an online (remote) repo. Git knows we have a local (on your computer) repo because we did git init earlier. So, let’s make Git aware of this remote one on our Github. Go to the page that popped up right after you created your Github repo. You’ll see a link:

Creating a repository

Go ahead and copy that link. Then put this command in your terminal:

git remote add origin

Then paste in the link you copied and hit ‘enter’.

This command is simply telling Git that we have a remote repo that we would now like to push our local repo to. Make sense? Git needs to know that we want to commit (or load) files from our local (on our computer) repo to our remote (on Github) repo. Let’s do that. Type in:

git push origin master

This command will load up your local repo and push it over to your remote repo on Github. So now go back to Github and click on Novel right next to your username. Now you see that your ‘Novel’ repo has our 3 chapters on it!

From here you can continue to edit your files locally (on your computer) and then push them remotely (onto Github). Let’s do that once making another edit to our 3rd chapter. Copy/paste the below text to be the last line on chapter 3.

Thank goodness she had a fairy godmother.

One thing to keep in mind - you can’t just push your changes to Github from here. We have to do the two-step ‘saving’ process of adding and committing. Go back to your terminal, make sure you’re still in your ‘Novel’ folder and:

git add .


git commit -m "Adding fourth line to 3rd chapter"

Now we have appropriately added our changes to Git - now we push it to Github:

git push origin master

Refresh your repo page and you’ll see the changed message next to ‘chapter_3.txt’. Then click into it and you’ll see it now has our last line we just added.

Feel free to reference this post if you forget commands. It’ll become easier and make more sense with a little practice. Believe me, it wasn’t too long ago that I was where you are now. Soon, documentation like the stuff found on Github will make sense.

comments powered by Disqus