Getting Started – GitHub
This is a quick and easy tutorial to get up and running quickly with GitHub as your online repository. What will be covered is how to get up and running using GitHub and some of the concepts that exist when you use it. What I’ll be going through are as follows:
- GitHub Concepts
- Registering a GitHub Collaborator Account
- Registering a GitHub Organization Account
- Linking a Collaborator Account to an Organization Account
- Generating & Registering SSH Keys
- Creating a Repository
- Git Setup
- Connecting to a Repository
- Useful Git Links
- GitHub Help
A collaborator in GitHub is the same as a user with the added benefit of having his own public account. In other words a Collaborator has the ability to set up his own Repositories with their own Wiki sites per Repository. This is quite a nice feature seeing that I can be linked to my Organization for those things that I do on their stuff, but I can also have my own source for articles I write or open source projects that I own. The other really big thing that can be taken into consideration is that as a Collaborator you can join any current open source project and do some development for them.
An Organization is exactly what it says. It’s a grouping of Projects and the Collaborators that work on the Organization’s projects. GitHub allows you to manage teams, projects and repositories within the Organization, making it easier for the members of the Owners team to manage permissions. So, if you take the hierarchy in a GitHub Organization then you would have something like this:
In the image above you’ll see that each Collaborator can still have his own Repository, while also having access to the Organization’s repositories. In GitHub the members of the Owner Team has access to all Repositories as well as everything else, while Collaborators belonging to other teams will only have access to Repositories inside the Team.
Registering a GitHub Account
Go to the GitHub home page and select the “Pricing and Signup” option at the top of the page. Once the page has loaded you can select the type of account you would like and then follow the process that follows. In my case I selected the “Free Account” option seeing that I want to register an Organization in the next section of this short Tutorial. Once selected, just follow the easy steps to completion and that should create an account for you to use as is and to create Repositories on.
Registering a GitHub Organization Account
Now that you have an Account with GitHub you might choose to create an Organization. So, once logged into your Account, you should select the “Account Settings” option at the top. Once the page has loaded you can select the “Organizations” tab, which will take you to the “Your Organizations” page where you can now select to “Create New Organization” where you can now choose your plan and follow the steps.
Linking a GitHub Account to an Organization Account
Now that you’ve created an Organization, you can add Collaborators. So, if you go to your Organization’s GitHub home page, usually at: https://github.com/organizations/YourOrganizationName, you should select to go to the “Teams” tab. Once there you can now create a team by selecting the “New Team” button which will take you to a page where you can setup a new team, add Members (Collaborators) to the team and add Repositories. You can also manage the types of permissions that the team can grant.
Generating & Registering SSH Keys
I will only be covering the generation of SSH Keys on an Ubuntu environment seeing that I don’t do this kind of development on my Windows environment. So, to start you should go into your Ubuntu environment and open a “Terminal Window”. Once this is open you can enter the following command which should take you to the folder where your SSH Keys should live:
Once there you can run the following command, replacing the email@example.com part with your own email address.
ssh-keygen -t rsa -C “firstname.lastname@example.org”
When it asks you for the file name you would like to use you should enter “id_rsa”. I usually leave the passphrase section empty. Once this has been completed you should now have two file named: “id_rsa” and “id_rsa.pub” in your “.ssh” folder. If you open the file ending with “.pub” you’ll see your public key. You should copy this seeing you’ll be using this key when you register a new key on your Account in GitHub.
To add this key to your GitHub Account you should go back to your Account Settings page in GitHub. Once there you should see an option for SSH Public Keys where GitHub will show you an RSA fingerprint and give you the option of adding another public key. When you select that you should type in any “Title” and paste your generated Public Key into the “Key” box and select Add key. Your Ubuntu machine should now be able to validate itself against your use account in GitHub. To test this you can type the following command into your Terminal window in Ubuntu:
This should come up with a message stating: “The authenticity of host ‘github.com (126.96.36.199)’ can’t be established.” Accept the “Are you sure you want to continue connecting (yes/no)?” question that comes up by stating “yes”. If you get the message –
”Warning: Permanently added ‘github.com,188.8.131.52’ (RSA) to the list of known hosts”
– you know that it has worked and that your machine can now authenticate itself against the GitHub servers. You should only ever see this message once.
Creating a Repository
This is a very simple process. Once you’ve logged into your account, you should go to the Organization’s dashboard. Once the page has finished loading you will see a “New Repository” button on the right hand side of the page.
If you click on the button you can simply follow the process to finish creating the Repository. A thing to note on this page is that you should select the relevant team this Repository belongs to.
You can change this at a later stage, but for now you can select the relevant team, which will then automatically allow that team to work on the “Project”. Once your Repository has been created you should follow the steps in the next section that covers setting up your development environment to start working against this new Repository.
Now that you’ve created your Repository on GitHub and you’ve added your SSH Key to your Account, you’re ready to connect to your Repository from your Ubuntu machine and hopefully start coding. So, to do this you’ll need to do a few things first. Open a Terminal Window and type in the following command to download and install Git:
sudo apt-get install git
Once you’ve downloaded and installed Git, you should configure it to use the same User Name and email address that you registered your GitHub account with. To do this you should run the following command to configure your User Name:
git config –global user.name “YOURUSERNAME”
To configure your email address you should run the following command:
git config –global user.email “YOUREMAILADDRESS”
This should conclude the install and configuration of your Git environment.
Connecting to a Repository
This is where it becomes a little bit more interesting. To connect to a Repository in GitHub you’ll now have to go to the folder that you’ll be using as your development folder. In my case I’m using “~/projects”. Once there you should create a folder for this specific Repository which will be “Hello-World” in this scenario. You can do this by running the following command from your Terminal Window:
Once your “Hello-World” folder has been created you should go into it and run the following command from your Terminal:
This will initialize a local Git Repository for you. Once done you should see a hidden folder called “.git” in your folder when you run the “ls –a” command. Now you can create your first file by running the following command:
You should add this file to your local Repository by running the command:
git add README
Once done you should commit this “add” operation to your local Repository by running:
git commit –m ‘first commit’
Now that you’ve created a local Repository and committed your first file to it, you will want to push this up to your remote GitHub Repository. To do this, you need to link your local Git Repository to your remote GitHub Repository. To do this you will to run the following command:
git remote add origin email@example.com:YOURORGANIZATIONNAME/Hello-World.git
Now that you’ve linked your local Repository you can push by simply running the following command:
git push origin master
That’s it to get you up and running quickly. For more information you can go to the sites listed below.
Useful Git Links
This should cover most of what you need to do to work with Git.
Git Reference Site
Working with remotes
For further help on using GitHub I would strongly suggest you go to the GitHub help section for further assistance. They have a lot of information there that should help you through most of the things you need to do.