How to Setup and Use Github in Ubuntu

If you are or want to be open source developer,you must try GitHub. It is a new hosted Git repository service that's being called a "social network" for programmers. It is basically a distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Setup SSH key

Generate SSH Key

If you have created your account at github and now you want to work with it from your terminal.

Before you start installing Github, you should set up ssh keys:

xiehaozhe@XieHaozhe-Think:~$ cd .ssh
xiehaozhe@XieHaozhe-Think:~/.ssh$ ssh-keygen -t rsa -C "zjhzxhz@gmail.com"

And you will get following output:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/xiehaozhe/.ssh/id_rsa): github
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in github.
Your public key has been saved in github.pub.
The key fingerprint is:
a5:93:9a:e1:b6:23:f7:ac:48:2e:5a:dc:70:18:dd:26 zjhzxhz@gmail.com
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|   . .           |
|  . E o   .      |
|   o o   +       |
|  o . . S        |
| . + . + .       |
|  o o =          |
| ..o.ooo         |
|.. .ooo+o        |
+-----------------+

Add your SSH Key to GitHub

Look up your SSH key in id_rsa.pub file:

xiehaozhe@XieHaozhe-Think:~/.ssh$ cat github.pub

Copy the SSH public key to clipboard, and Open https://github.com/settings/ssh

Click "Add SSH Key", and paste your SSH key.

Github-SSH-Key

Test connection to GitHub

ssh -vT git@github.com

If you got an error: Agent admitted failure to sign

For most users, simply running ssh-add to load your keys into the SSH agent will fix this issue.

$ssh-add
# Enter passphrase for /home/you/.ssh/id_rsa: [tippy tap]
# Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa)</pre>
If your key does not have the default filename, you'll have to pass the path to <code>ssh-add</code>
ssh-add ~/.ssh/my_other_key
# Enter passphrase for /home/you/.ssh/my_other_key: [tappity tap tap]
# Identity added: /home/you/.ssh/my_other_key (/home/you/.ssh/my_other_key)

Or, you will got a welcome message:

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

Install Git

sudo apt-get install git

Working with git

Cloning

$ git clone git@github.com:username/projectname.git

To configure git

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

To do a scripts/reconfig, make, perform some changes to the code, ...

git add new_or_existing_file.c
git commit
git push origin master

Occasionally you will want to sync up your fork to the main project branch and pull down any official changes by doing git pull upstream master which is the equivalent of manually doing:

git fetch upstream
git merge upstream/master

You can get more information about Git in: http://rogerdudler.github.io/git-guide

Contact Us
  • Room 614, Zonghe Building, Harbin Institute of Technology
  • cshzxie [at] gmail.com