Secondary Menu

Introduction to GitHub

About: Scott Kildall is an new media artist and researcher. He works at Autodesk, Pier 9 and is an artist-in-residence with the SETI Institute
More About scottkildall »

I've been using people's code from GitHub for a couple of years and without it, I'd be totally stuck in my various projects. I want to give back.

I had a mixture of confusion and laziness around how GitHub works, which got in my way. I eventually figured it out, but it took some bumping around.

This Instructable will explain the basics of creating a Git repository, how it works and how to upload it onto GitHub.

I'll be using the commands from the Terminal application on the Mac, but the principles can be extended to other platforms as well.

What is Git vs. GitHub?Git is a source code version control system, which a series of "commits" or snapshots of your code. You make the commits manually.

GitHub is a website (github.com) where you can publish your Git repositories for public download and possible collaboration.

Step 1: Create a Repository on the GitHub Site

First, you'll want to register for a GitHub account. You can create as many repositories you want, as long as they are public. Anyone can download your public link and use your code and contribute to the archive. I usually don't upload a repository (a.k.a. a "repo") unless I'm at a good point with the code and ready to make it public.

Specific Steps on the GitHub site Log in Go to the Repositories tab Click on the green New button, which will bring up this dialog Enter a name for your source code repository Select the Public radio button Enter a 1-sentence description Check the Initialize the repository with a ReadMe file Choose the green Create Repository button

Now, you have an new repository. A default README.md file will be displayed in GitHub

If you type in: ls then you will see a list of all the files in your directory, which helps to verify that you're in the right place.

Step 4: Initialize Git

In the Terminal window, type in:

git init

This will create hidden files that Git uses to manage its source code control. The idea is that you will have a single local directory which you will sync with the one on your GitHub account.

If you delete or replace the contents of this directory, it will mess up your configuration, so try to avoid anything like this.

You only need to do this once for each Git repo on your local drive.

Step 5: Pull the ReadMe.md File From Your GitHib URL

In this case, a "pull" request means that you are downloading files from GitHub into your local directory and a "push" request means that you are uploading files from your local directory onto GitHub

In the terminal, type in:

git remote add origin https://github.com/<username>/<repo name>.git

where <username> is your GitHub account username and <repo name> is your repository name that you just created.

In the case of lenenbot, this would be:

git remote add origin https://github.com/scottkildall/lenenbot.git

To communicate with the outside world, Git uses remotes. These are repositories other than the one on your local disk which you can push your changes into (so that other people can see them) or pull from (so that you can get changes from others). This is essentially how this system works for Git and GitHub.

The command git remote add origin creates a new remote called origin located on GitHub.

Once you do this, you can push to origin instead of typing out the whole URL.

Now, type in:

git pull origin master

This command will download the contents of your newly-created repository into your local directory. In this case, it is just the README.md file.

Note: You can have your source files in your current directory, the download won't replace existing files (except for an existing README.md file).

Organization Contest

5 Discussions

Well done basic tutorial... However, it is worth noting to viewers that Git does not require GitHub or even a server, and can be used locally. It would be a good idea to eventually explain some of the more powerful capabilities of Git such as interactive staging, branches, tags, .gitignore, merging, rebasing, resetting, and stashing.

There is a good book that I read that can be found on git-scm.com called Pro Git. I wanted to set up a server, so I read the whole thing (around 300 pages), but the first 3 chapters will give a you a basic understanding.

Also, in terms of a GUI tool, I have found that 2 in particular seem to work well.

Mac and Linux - Git Cola

Windows - Git Extensions

Note that Git Extensions will give you the option to install Git and a tool called KDiff3. I cannot say anything about the included Git installation due to the fact that I just installed it using the default installer from the git-scm website. I would not suggest installing KDiff3. Although it is very powerful, I have had issues with it - it seems that it doesn't like to apply the last change.

However, I have recently discovered a tool called Meld available for Mac, Windows, and Linux that provides a much nicer (if less powerful) interface. I would suggest using that for merging.

One more consideration: look into Mercurial (also referred to as hg). It is far simpler than Git but less powerful. Just note that it is less common than Git, so sometimes you may run into compatibility problems. However, tools exist (specifically git-hg and hg-git) that allow you to work with other repos through your SCM tool of choice.

For those who don't know:

SCM = Source Code Management

CVS = Central Versioning System

SVN = Subversion (a common CVS tool)

DVCS = Distributed Version Control System (Git and Hg are examples of this, and have many benefits over CVS-based systems)

Git does not stand for anything. Its name is a self-insulting remark by Linus Torvalds (the creator of Git and Linux).