Friday, September 2, 2011

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.
Github
Setup SSH key....
So, 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:
  1. $cd ~/.ssh
    if it says "bash: cd: ./.ssh:No such file or directory",it means its not generated and you should continue with step 2. But if it changes to ~/.ssh directory, continue from step 3.
  2. open your terminal any type
    $ssh-keygen -t rsa -C "your_email@youremail.com"
    you will get following lines: 'Generating public/private rsa ket pair. Enter file in which to save the key(/Home/ubuntu/.ssh/id_rsa):' just press enter now it will ask you to enter passphrase note that passphrase you enter must be >4, otherwise you will have to repeat whole process again.
  3. Backup and remove existing SSh keys type 'ls' it should show you some files like now type these following commands one by one
    $ mkdir key_backup
    $ cp id_rsa* key_backup
    $ rm id_rsa*
  4. Adding your ssh key to Github
    $gedit id_rsa.pub
    copy its entire content. Open github site and login. go to “Account Settings” > Click “SSH Public Keys” > Click “Add another public key” an paste it  into "key field". then press Add key.
Now you have successfully setup ssh key and ready to install github in terminal.
Installation...
In your terminal type following command
$ sudo apt-get install git-core git-gui git-doc
Working with git...
Cloning:
In terminal type
$ git clone git@github.com:username/projectname.git
to download a local copy of your code branch. You'll need to replace "username" with your GitHub user name and project name with the name of project on github.
To configure git:
Setup git with your name and email address
  1. git config --global user.name "Your Name"
  2. git config --global user.email "your@email.com"
To do a scripts/reconfig, make, perform some changes to the code, ...
Modify or create a file and then push it to your project fork on GitHub.
  1. git add new_or_existing_file.c
  2. git commit
  3. 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
Here are some useful queries you can do to see the git state of things:
  • git remote -v to see your fetch and push remotes
  • git status to see what you have recently changed
  • git log to see a list of all committed changes done to your fork
  • git log --stat a more detailed list of all committed changes done to your fork
  • git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s" a colorful text-base graph of changes. See image on the right.

No comments:

Post a Comment

Post a Comment