Advertisement
ygamretuta

Git Snippets

May 25th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.48 KB | None | 0 0
  1. # undo remote push
  2. git reset <commit_hash>
  3. git push -f <remote_name> <branch_name>
  4.  
  5. # undo remote push preserve changes
  6. git reset <commit_hash>
  7. git stash
  8. git push -f <remote_name> <branch_name>
  9. git stash pop
  10.  
  11. # alias for restoring files on git ( git restore-file my-file )
  12. git config alias.restore-file '!git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"'
  13.  
  14. # keep changes only in local repo, do not include file changes on commit
  15. git update-index --assume-unchanged <file>
  16.  
  17. # undo update-index
  18. git update-index --no-assume-unchanged <file>
  19.  
  20. # undo commit, delete changes
  21. git reset --hard HEAD~1
  22.  
  23. # undo commit, keep changes
  24. git reset HEAD~1
  25.  
  26. # undo commit, keep changes and indices
  27. git reset --soft HEAD~1
  28.  
  29. # delete all local branches starting with 'feature/'
  30. git branch | grep 'feature/' | xargs git branch -d
  31.  
  32. # rename local branch if not in branch
  33. git branch -m <oldname> <newname>
  34.  
  35. # rename local branch if in branch
  36. git branch -m <newname>
  37.  
  38. # push current branch to remote
  39. git push origin HEAD
  40.  
  41. # remove all .swp files
  42. git ls-files | grep '\.swp$' | xargs git rm
  43.  
  44. # write and quit vim, press Esc then
  45. :wq // then press Enter
  46.  
  47. # stash changes
  48. git stash save --keep-index
  49.  
  50. # undo push
  51. git push -f origin last_known_good_commit:branch_name
  52.  
  53. # alias multiple commands in .git/config
  54. [alias]
  55.         kuzza = !git checkout develop && git fetch origin develop && git merge
  56.  
  57. # fetch and merge remote
  58. git fetch <remote> <branch>
  59. git merge <remote>/<branch>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement