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 the current branch:
    • git branch -m newname 
    • where newname is the name of the branch
  • Undo 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 the path to them, just copy it and use as  pathToFile  )
  • How change message from the last commit to 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
  • A nice shortcut for quick commit, where you add all files and commit them to the 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 a shortcut for Reference logs.
    • git reflog
  • How to clean in optimise repository. (-- aggressive should be used once per few hundreds commit) 
    • git gc --aggressive
  • How Using command line but prefer to have a 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
  • How to clean in optimise repository. (-- aggressive should be used once per few hundreds commit) 
    • git gc --aggressive
  • To avoid messy merge commits and help keep a relatively clean git commit history use the following workflow when fetching upstream changes:
    • git fetch origin and then git rebase -p origin/develop
  • Fancy change author name of commit?
    • git change-commits GIT_AUTHOR_NAME "old name" "new name"
  • Get fed up with merge the same conflicted changes over and over again? Enable this feature make you life less painful.
    • git config --global rerere.enabled true