20 March 2014

Git notes

This is personal notes for personal and my friends only:
You can read them,but I suggest look to link,resources only

Git is a distributed revision control and source code management tool.


  1. Pro Git (book is free,but if you use ,please buy it)


Useful command and command combos:
  • Change name of current branch:
    • git branch -m newname 
    • where newname is name of the branch
  • Unmodify modified file
    • git checkout -- pathToFile
    • where pathToFile is a file (path to file,that should be deleted (git status display all modified file  or actually path to them,just copy it and use as  pathToFile  )
  • How change message from last commit in Git?
  • -force-with-lease
    • use -force-with-lease instead -force-force-with-lease effectively only allows you to force-push if no-one else has pushed changes up to the remote in the interim.
  • How to remove all untracked files
    • git clean -df
  • Nice shortcut for quick commit , where you add all files and commit them with message.
    • git commit -a - m "Describe your job or title from Jira "
  • How to cancel and undo merge ,if you have conflict problems  
    • git merge --abort
  • Delete all uncommitted changes  
    • git checkout -- .
  • How to recover from shit happens like lost commit ? Use Reflog which is shortcut for Reference logs.
    • git reflog
  • How to clean in optimise repository. (-- aggressive should be use once per few hundreds commit) 
    • git gc --aggressive
  • How Using command line but prefer to have more readable output of commits ? Use this:
    • git log --graph --pretty=format:'%C(bold blue)%an%Creset %C(green)%cr %C(red)[%H]%Creset -%C(dim yellow)%d%Creset%n   %C(ul magenta)%s%Creset ' --abbrev-commit --date=relative