Friday, 23 March 2012

Git: Most oftenly used commands


Global setup:

 Set up git
  git config --global user.name "sonu"
  git config --global user.email sonukr666@gmail.com

Next steps:

  mkdir dfd
  cd dfd
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:sahilsonu/dfd.git
  git push -u origin master

Existing Git Repo?

  cd existing_git_repo
  git remote add origin git@github.com:sahilsonu/dfd.git
  git push -u origin master
      

Importing a Subversion Repo?

  Check out the guide for step by step instructions.
      

When you're done:

  Continue
  1. Check for SSH keys. Have an existing key pair? You can skip to Step 4. First, we need to check for existing ssh keys on your computer:
    $ cd ~/.ssh
    
    If it says “No such file or directory“ skip to step 3. Otherwise continue to step 2.
  2. Backup and remove existing SSH keys. Since there is already an SSH directory you’ll want to back the old one up and remove it:
    $ ls
    
    $ mkdir key_backup
    $ cp id_rsa* key_backup
    $ rm id_rsa* 
     
  3. 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@youremail.com"
    
    
    
  4. Test everything out. To make sure everything is working you’ll now SSH to GitHub. Don’t change the “git@github.com” part. That’s supposed to be there.

    $ ssh -T git@github.com 
  5. Reverting changes:
    1. Reverting unstaged changes we just mad
           $ git checkout -- fileName.txt
    2. Reverting Changes of entire working dir     $ git checkout -- .
           OR     $ 
      git checkout HEAD
    3. Reverting staged changes( git add. )      git reset fileName.txt
           git checkout fileName..txt  // And then checking it out,leaving other untouched
      OR
       To revert all changes:     
      git reset --hard HEAD
    4. Reverting changes in nascent directory where there is No HEAD   git rm --cached fileName.txt
 
Reference:
 
http://help.github.com/git-cheat-sheets/ 
Reverting Changes:  http://www.szakmeister.net/blog/2011/oct/12/reverting-changes-git/

No comments:

Post a Comment