Monday, February 9, 2015

Configure Git for daily usage


sudo <packagemanager> install git
eg: sudo yum install git

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global core.editor vim
 
git config --global diff.tool kdiff3
git config --global merge.tool kdiff3
git config --global --add difftool.prompt false 
 

More aliases

git diff <path to file> 
This will show the diff between the uncommited file and the one that was present after checkout
git diff --cached 
This will show the diff between the committed file and the checkout one.
git pull 
 

Workflow

Usual:
 git checkout -b <branchname>
      work on stuffs 
 
 git add <file1>
 git add <file2>
 
 git commit -m "commit message -- description of what the commit is about"
 
 git push -u origin branch
 
  
Before doing a git push,
 
 git stash -- this will stash all the tracked files to your local directory.
 
 git pull -- this pull will not have any merge conflicts.
 
 git stash apply
 
 git difftool <filenames> 
 
 verify your changes
 
 Now follow the usual procedure
 
 

Git FAQs:

1) How to pick a commit from one git repo to other.
 
 git --git-dir=../some_other_repo/.git \
format-patch -k -1 --stdout <commit SHA> | \
git am -3 -k