I started using growing interest for Open Source softwares sometime before and then i came across the terms VCS (Version Control System) and eventually my path stopped at GIT. I was glad to see to see github and its uses around.

github image

So i did some basic setup which are in fact not so complicated but there is no single guide that I found online. So, here I decided to provide a single guide based on a number of website references.

The best place to learn is the official doc help from github.com but i got pretty confused for the first time with the whole setup.

If you are new to git and don’t have a clue what it is, you can learn what git from here, http://git-scm.com/book/en/Getting-Started-Git-Basics

Good so now you know what git is and then go ahead and download the latest version of git from here, http://git-scm.com/downloads

Alright, now we are good to go. Open the terminal and start by configuring git.

Username

First you need to tell git your name, so that it can properly label the commits you make.

git config --global user.name "Your Name Here"
# Sets the default name for git to use when you commit

Email

Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.

git config --global user.email "your_email@example.com"
# Sets the default email for git to use when you commit

Your email address for Git should be the same one associated with your GitHub account. If it is not, see this guide for help adding additional emails to your GitHub account. If you want to keep your email address hidden, this guide may be useful to you.

Password caching

The last option we need to set will tell git that you don’t want to type your username and password every time you talk to a remote server.

Tip: You need git 1.7.10 or newer to use the credential helper

To use this option, you need to turn on the credential helper so that git will save your password in memory for some time:

git config --global credential.helper cache
# Set git to use the credential memory cache

By default git will cache your password for 15 minutes. You can change this if you like.

git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)

Now git is set and ready for use. Github recommends to use https instead of SSH but i personally feel better using ssh. So, now we are goin to generate some ssh keys for the same use.

Generating SSH Keys

Step 1: Check for SSH keys

First, we need to check for existing ssh keys on your computer. Open up Terminal and run:

cd ~/.ssh
ls
# Lists the files in your .ssh directory

Check the directory listing to see if you have a file named either id_rsa.pub or id_dsa.pub. If you don’t have either of those files go to step 2. Otherwise, you already have an existing keypair, and you can skip to step 3.

Step 2: Generate a new SSH key

To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.

ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/home/you/.ssh/id_rsa):
ssh-add id_rsa

Now you need to enter a passphrase.

# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]

Which should give you something like this:

# Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

Step 3: Add your SSH key to GitHub

Run the following code to copy the key to your clipboard.

sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

Alternatively, using your favorite text editor, you can open the ~/.ssh/id_rsa.pub file and copy the contents of the file manually

  1. Account settings buttonGo to your Account Settings
  2. SSH Keys menuClick “SSH Keys” in the left sidebar
  3. SSH Key buttonClick “Add SSH key”
  4. The key fieldPaste your key into the “Key” field
  5. The Add key buttonClick “Add key”
  6. Confirm the action by entering your GitHub password

Step 4: Test everything out

To make sure everything is working you’ll now SSH to GitHub. When you do this, you will be asked to authenticate this action using your password, which for this purpose is the passphrase you created earlier. Don’t change the git@github.com part. That’s supposed to be there.

ssh -T git@github.com
# Attempts to ssh to github

It’s possible that you’ll see this error message:

...
Agent admitted failure to sign using the key.
debug1: No more authentication methods to try.
Permission denied (publickey).

This is a known problem with certain Linux distributions. For a resolution, see our help article.

You may see this warning:

# The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?

Don’t worry, this is supposed to happen. Verify that the fingerprint matches the one here and type “yes”.

# Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.

If that username is correct, you’ve successfully set up your SSH key. Don’t worry about the shell access thing, you don’t want that anyway.

Now you can use ssh keys 🙂

Lets start by creating your first repository.
Click on create new repository on github.com
Enter the necessary details and it’s done. Now open terminal and type
git clone git@github.com:<username>/<repo_name>
You might be asked to enter your password and the repo has been cloned to your local drive. Next time when you edit something or do some changes, Add to git by,
git add .
git commit -m “<your commit text>”
Sometimes you might get some error like content can not be added by due to some error. Use,
git commit -a
This will clear and then you can probably use pull to pull any changes done to the site and then you can proceed pushing your local changes.
git push origin master
to push your changes to the site.

You can view your changes to the site also. 🙂 That’s more or less everything you need to get the basic stuffs done on git or github 😀