You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.5 KiB

  1. # @noroadsleft's Git aliases
  2. [Return to the directory index.](./)
  3. ```
  4. [alias]
  5. # Change branches
  6. co = checkout
  7. cob = checkout -b
  8. # Cherry Pick
  9. cp = cherry-pick
  10. # Check out a Pull Request locally
  11. # e.g. `git cop 351` fetches the commits from Pull Request #351 and saves it to local branch 'pr/351'.
  12. cop = "!f() { git fetch upstream pull/$1/head:pr/$1; git checkout pr/$1; }; f"
  13. # Sync master branch
  14. sync = !git checkout master && git fetch upstream 2> /dev/null && git pull -n upstream master && git push origin master
  15. # Return the abbreviated SHA-1 of the last three commits, oldest to newest
  16. rl = rev-list -n 3 --abbrev-commit --reverse HEAD
  17. # Add remote repo (for sending PRs to other forks, or checking out someone else's developments)
  18. ar = "!f() { git remote add $1 https://github.com/$2/qmk_firmware.git; }; f"
  19. # Return the last five commits on the branch, in a more compact format
  20. hist = log --pretty=format:\"%C(yellow)%h%Creset %Cgreen%ad%Creset %Cblue[%an%Cgreen% GK%Cblue]%C(yellow)%d%Creset%n %w(100,0,2)%s%n\" --graph --date=iso-local -n 5
  21. histt = log --pretty=format:\"* %C(yellow)%h%Creset %<(58,trunc)%s %Cblue%>(18,trunc)%an%Cgreen% G?%Creset @ %Cgreen%ad%Creset\" --date=iso-local -n 5
  22. histb = log --reverse --pretty=format:\"- %Cblue%>(20,trunc)%an %Creset%<(97,trunc)%s\" --date=iso-local -n 5
  23. # Follow a file's filename history
  24. follow = log --follow --name-only --pretty=format:\"%C(yellow)commit %H%Creset%d\nAuthor: %an <%ae>\nDate: %ad%n%n %s%n\" --date=iso-local
  25. # compact diff
  26. df = "diff --compact-summary"
  27. # List all the files changed in a commit
  28. dt = "diff-tree --no-commit-id --name-only -r"
  29. # Short-form status
  30. st = "!git status --short --untracked-files=no"
  31. stu = "!git ls-files --others -x '*/*'"
  32. # Returns the name of the current branch
  33. branch-name = "!git rev-parse --abbrev-ref HEAD"
  34. bn = "!git branch-name" # short-form of the above
  35. # List branches by the date of their last commit, newest to oldest
  36. bbd = "for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(objectname) %(objecttype) %(refname:short) (%(authordate))'"
  37. # Compare commit counts between current branch and QMK master
  38. # e.g. `git cc dev_branch upstream/master` returns how many commits are on `dev_branch` and not on `upstream/master`, and vice versa.
  39. cc = "!f() { git fetch upstream; echo \"$(git branch-name) vs. $2\"; git rev-list --left-right --count $1...$2; }; f"
  40. # Push to origin repo
  41. po = "push origin $(git branch-name)"
  42. # List the stashes
  43. sl = "stash list"
  44. # Unstage a file
  45. unstage = "reset HEAD"
  46. # Restore a file to the state it was in when checked out
  47. restore = "checkout --"
  48. # Compare local master repo to its upstream branch. If anything is returned, local branch has diverged from upstream.
  49. cm = "!f() { git fetch upstream master; git diff $(git branch-name) upstream/master --compact-summary; }; f"
  50. cml = "!f() { git fetch upstream master; git diff $(git branch-name) upstream/master; }; f"
  51. # Delete a branch from local and remote
  52. del-branch = "!f() { git branch -d $1; git push origin :$1; git fetch -p origin; }; f"
  53. # Rebase with signatures
  54. rbv = rebase --exec 'git commit --amend --no-edit -n -S' -i
  55. # Force push without overwriting established history
  56. pushf = push --force-with-lease
  57. ```