document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. get existing branch from remote
  2. git checkout -b <branch> origin/<branch>
  3.  
  4. replace current commit with the files currently in the directory
  5. git commit --amend -C HEAD
  6.  
  7. change commit message
  8. git commit --amend
  9.  
  10. take all changes to tracked files and make a commit
  11. git commit -all
  12.  
  13. what chnages are going to be committed
  14. git diff --cached
  15.  
  16. changes files in the working tree and the last commit
  17. git diff head
  18.  
  19. cleaning git -d directory , -x - untracked and ignored, -f forced (-n only shows files)
  20. git clean -dxf
  21.  
  22. git log --oneline
  23.  
  24. update all remotes
  25. git fetch -all
  26.  
  27. reset merge to return to the stae before merging
  28. git reset --merge
  29.  
  30. remove untracked changes in the working directory
  31. git stash --keep-index
  32. bring back the stashed changes to the working tree
  33. git stash pop
  34.  
  35.  
  36. difference between local master and origin/master (or any other branch)
  37. git diff master origin/master
  38. git diff master file (on branch)
  39.  
  40. git log
  41. git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
  42.  
  43. git list branches (-a all local and remote, -r only remote branches)
  44. git branch -a
  45. git branch -r
  46.  
  47. git show files in directories
  48. git st -u
  49.  
  50. git rebase on master local
  51. git rebase origin/master
  52.  
  53. push new branch
  54. git push -u origin your_branch
  55.  
  56. git stash - store uncommited changes (clean local repo)
  57. git stash
  58. git stash list
  59. git stash apply (last stash otherwise explicitly cite which one)
  60. git stash drop - drop last one
  61. git stash clear - remove ALL
  62.  
  63. git stash apply SHA1 - in case you dropped the stash
  64.  
  65. git push branch
  66. git push origin branch_name
  67.  
  68. git diff modified and last commit
  69. git diff HEAD file
  70.  
  71. after rebase , push
  72. git push origin your_branch --force
  73.  
  74. keeps history visible on graph
  75. git merge --no-ff
  76.  
  77. remove last commit
  78. git reset --hard HEAD~1
  79. or use soft if you want to keep changes
  80.  
  81. git track remote branch (create new one)
  82. git checkout --track origin/daves_branch
  83.  
  84. git move files
  85. git mv FILE destination
  86.  
  87. git rebase before pushing (only commits which differ from upstream - master)
  88. git rebase -i @{u}
  89.  
  90. fix conflicts during merge
  91. git mergetool
  92.  
  93. commit deleted files
  94. git add -u
  95.  
  96. git any commit diff (example diff last commit with previous)
  97. git difftool HEAD HEAD~1
  98.  
  99. git diff label
  100. git diff tag1 tag2 -- some/file/name
  101.  
  102. last commit change
  103. git commit --amend
  104.  
  105. git rename (folder,files)
  106. git mv old new
  107.  
  108. git diff file wiht previous
  109. git diff HEAD~2 main.c
  110.  
  111. show tags (label)
  112. git tag
  113.  
  114. git annotated tag (not lighweight!)
  115. git tag -a v1.4 -m 'my version 1.4'
  116.  
  117. git diff staged
  118. git diff --cached file
  119.  
  120. squash merge
  121. git checkout master
  122. git merge --squash newstuff
  123.  
  124. show untracked files
  125. git ls-files --other --exclude-standard
  126.  
  127. only files name which differs
  128. git diff --name-only master <branch>
  129.  
  130. brach remove from remote
  131. git push origin :newfeature
  132.  
  133. delete branch
  134. git brach -d branch_name
  135.  
  136. show branch with commits
  137. git show-branch
  138.  
  139. show which branch was merged (be concious about squash/rebase)
  140. git branch -r --merged master | sed 's/ *origin\\///' | grep -v 'master$'
  141.  
  142. get tag
  143. git fetch -t
  144.  
  145. push tag
  146. git push origin [tagname]
  147.  
  148. git github forked update (new upstream, then merge to master fork) - mbed as an example
  149. git remote add --track master upstream git://github.com/mbedmicro/mbed.git
  150. git merge upstream/master
  151.  
  152. git (github) update fork
  153. git fetch upstream
  154. git merge upstream/master
  155.  
  156. revert bad rebase
  157. git reflog (this displays history, check which one you want to return to)
  158. git reset <sha> --hard
  159.  
  160. show commit with sha (example 1e8e50996)
  161. git show s1e8e50996
  162.  
  163. fetch a branch github (already forked)
  164. git remote add theirusername git@github.com:theirusername/reponame.git
  165. git fetch theirusername
  166. git checkout -b mynamefortheirbranch theirusername/theirbranch
  167.  
  168. set tracking branch (current branch to track upstream/foo)
  169. git branch -u upstream/foo
');