GitHub is a place where you can put your code, and share it with other people. GitHub is free for open source code. This means that with a free account, when you put your code on GitHub, anyone on the internet can see it.
I’m a developer, and I’m lucky because I like my job so much I do it as a hobby too. If I have spare time I like to get my laptop out and mess around with whatever technology or idea has caught my attention recently, by building fun little projects and writing play code.
GitHub has been around since 2009, but it was only about 3 months ago, on 15th April 2012, that I started putting my little projects and play code on there. I’m really angry at myself for not doing it sooner.
Why didn’t I do it sooner? Well, the fact that anyone on the internet would be able to see my code scared me. I thought that my code wasn’t good enough for public consumption; that it was too messy, not ready, and not polished or complete enough. I was too self-concious and embarrassed.
Why is it good to put your code on GitHub?
- You will have a comprehensive record of what you’ve done
- Other people will be able to see what you’ve done and give you credit for it
- Maybe someone else would like to work on your code too; this’ll make it easier
- It’s sociable. You can be GitHub buddies with others. On GitHub I’m seeemilyplay, btw
All the code I’ve made over the years; some of it is languishing on old hard-drives, but most of it is just gone. I’d love to be able to go back over it now, and see if there’s any ideas I might want to resurrect, and see how I’ve learnt and changed over time. Oh yes, I really regret not using GitHub sooner.
So with all the zeal of a convert, I have been encouraging others to put their code on GitHub too. I’ve found that there are three main blockers people have …
Common GitHub Block 1: Feeling the code isn’t good enough
This is the feeling that your code isn’t good enough or requires more work before it can be made public. These high expectations on the required quality of the code prevent anything making it to GitHub.
The best way around this is to set yourself a rule: everything you write, no matter if you think it’s bad or it’s too early, should go on GitHub. If you’re feeling unsure about things, just feel the fear and do it anyway. After a while you’ll get used to it. I know that you’ll be dwelling on all your code’s imperfections, but it’s a little like when you have zits at a party, the blemish looks big to you, but it’s likely that no-one else will really notice or care much. The important this is this: don’t let your zits stop you going to that party and having fun!
Common GitHub Block 2: Feeling you’re not experienced enough
This is common amongst beginner coders. The perception is that you have to be experienced before you can put your stuff on GitHub. This is really not true.
Just think, won’t it be fantastic in a couple of years time to be able to go look back at how you learnt? It’ll be such an amazing record for yourself. Also, I promise, no-one’s going to be judging your early code unkindly. Yes, you’ll make a lot of mistakes and crappy code, but everyone does to start with, all the experienced coders understand completely what it’s like to learn coding, because they had to too; we all start off as beginners.
Common GitHub Block 3: Not sure how to use it
You can’t use GitHub if you don’t know how! But thankfully this is the easiest block to remove, all it takes is a little learning, and I can help you get started with this! Here goes…
Tips to get you going with GitHub
The first thing to know is that to use GitHub you’ll need to use a separate piece of software called Git. Git is a version control system. This means that as you edit code it can take care of tracking and recording all your changes in a formal way. You can use Git without GitHub.
This means your very first task is to install and setup Git on your computer. GitHub provides good instructions on how to do this, but here’s a brief version:
Installing and Setting Up Git
1. Download and install
If you’re on a Mac download the .dmg from here, and install as usual. If you’re on Windows download the .exe from here, and install by running it. If you’re on Ubuntu you can install with apt-get by running:
$ sudo apt-get install git-core
2. Check your installation
Open up a terminal and check Git is installed by running:
$ git --version
You should get a reply that explains which version of Git you’re running.
Tell Git a little about yourself with the following two lines on the terminal:
$ git config --global user.name "Your Name Here"
$ git config --global user.email "email@example.com"
First Steps with Git
Now you’ve got Git setup you will need to learn a little about how to use it. There’s an incredible wealth of tutorials and information and even online books out there to help you with Git. Git’s one of those tools that you often pick up as you go along. Some people will eventually become real experts at it, and some people are happy to stick with knowing enough to get by. I recommend googling to satisfy curiosity, but in the meantime I’m just going to go through the bare minimum you’ll need to put your code on GitHub.
1. Open a terminal
2. Create a folder for you code, and cd into it
$ mkdir git-play-project
$ cd git-play-project
3. Tell Git that you would like it to track the code in this directory with:
$ git init
4. Now create a file named README.txt and save it inside the project folder, git-play-project. You can let Git know that it should look after this new file by saying:
$ git add README.txt
5. If you have an existing directory of code, you can do a
git init to initialise it, and then add all your files at once to Git with:
$ git add .
6. Ask Git what it thinks you’ve done so far by running:
$ git status
7. Once you’ve finished adding the files you want you can ask Git to officially record your adds as a change by saying:
$ git commit -am "Setup my project in Git"
The stuff between the quotes is a description of what you’ve been doing. Now your project is in Git.
8. What happens if you want to edit a file? Well, edit the file or files as you normally would, and then ask Git to record your edits as an official change with:
$ git commit -am "Put in better variable names"
Again the stuff between the quotes describes what you were doing with your changes.
Getting going with GitHub
Once you have Git going you can start with GitHub. You will need to sign-up for a free account on their website. They will provide instructions on how to setup your first repository. A repository is a place to keep the code for a particular project.
Now what you can do is get some code being looked after by Git on your computer and use Git to put a copy of that code into GitHub. Again, GitHub provides good instructions, but I’ll do a brief version here.
The first job is to open a terminal and let Git know about the GitHub repository that you just created with:
$ git remote add origin https://github.com/yougitname/Your-Repos-Name.git
Now you can tell Git to copy your latest code onto your GitHub repository using:
$ git push origin master
From now on after you commit changes to your local Git you can then ‘push’ this code to the GitHub repository by simply saying:
$ git push
Now, go to GitHub, and you should be able to see your code.
So there you are. Now please, go forth and get your stuff on GitHub!