Git in 2 days(Git Cheat Sheet)

First of all, i m very sorry for not updating my blog for a long time. I was very busy in office stuff, finally now am back with more concentration and Power.
Here I m sharing some commands for my new girlfriend GIT. i hope you like, if yes then don't forget to comment below.
If you know all this, may be its time to revise again.

git clone

// to clone a existing repository

git clone git:// mygrit

// clone a existing repo in
mygit folder or path specified at the end of command.

.gitignor file

//to ignore file like .a, .o
Example of .gitignor file. below is the content of git file.

How to work with Gitignore

# a comment
*.a //not no include .a files
!lib.a // but do track lib.a
/TODO  //only ignore the root TODO file, not subdir/TODO
build/  ignore all files in the build/ directory 
doc/*.txt //ignore doc/notes.txt, but not doc/server/arch.txt 

Git diff

git diff

// which the changes in current modification

git diff -staged

//only changes that are still unstaged

git commit -a -m ’added new benchmarks’

//adding all changed files and
commiting them for pushing on server

git rm

removing file from git directory

git rm --cached readme.txt 

//keep the file in your working tree
but remove it from your staging area. In other words, you may want to keep the file
on your hard drive but not have Git track it anymore

git mv file_from file_to


 git log

//Viewing the Commit History

git log p -2

//which shows the diff introduced in each

git log --stat

//to see some abbreviated stats

git log --pretty=oneline 

//to see formated log, change online to short, full, fuller

git log --pretty=format:"%h - %an, %ar : %s" 

// example fc2e357 - dkgndec, 4 days ago : First commit

git log --pretty=format:"%h %s" --graph 

//for graph with merge

git reset HEAD benchmarks.rb 

//The benchmarks.rb file is modified but
once again unstaged.

 git remote -v 

//to see all d remotes

git remote add pb git:// 

//Adding Remote Repositories

 git fetch pb 

//f you want to fetch all the information that david has but that you don’t yet
have in your repository

git fetch [remote-name]
git pull
 //generally fetches data from the server you originally cloned from and automatically tries to
merge it into the code you’re currently working on.
git remote show origin
git remote rename pb paul
git remote rm paul

GIT Tagging

git tag
git tag -l ’v1.4.2.*’
git tag -a v1.4 -m ’my version 1.4’

//Annotated Tags

git show v1.4 
git tag -s v1.5 -m ’my signed 1.5 tag’ 

//signed tag

git tag v1.4-lw 

//Lightweight Tags

git tag -v v1.4.2.1
git tag -a v1.2 9fceb02 

//add tag later

git push origin v1.5 

//push tags

git push origin --tags

//push all tags

Auto-completeion in GIT

Go to contrib/completion in git Copy git-completion.bash file to your home directory,
and add this to your .bashrc file: source ̃.git-completion.bash

Working with Git Alias

git config --global checkout

//making alias

git config --global alias.unstage ’reset HEAD --’
 git unstage fileA
git config --global alias.last ’log -1 HEAD’
 git branch testing

//add new branch

git checkout testing 

//change Branch

git merge branch_name
git checkout -b iss53 

//create a branch and checkout both

git branch -d branchname

// to delete branch

 git mergetool
git branch -v

//to see last commit on each branch

git branch --merged 

//To see which branches are already merged into the branch you’re

git branch --no-merged :
git branch -D testing
git fetch origin

//to gain data which you dnt have till now

git checkout -b serverfix origin/serverfix

git rebase master 

//changes that were committed on one branch and
replay them on another one