├── LICENSE └── git-aliases.zsh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Kite 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /git-aliases.zsh: -------------------------------------------------------------------------------- 1 | alias g='git' 2 | 3 | # git add 4 | alias ga='git add' 5 | alias gaa='git add --all' 6 | alias gai='git add --interactive' 7 | alias gap='git add --patch' 8 | alias gau='git add --update' 9 | alias gav='git add --verbose' 10 | 11 | # git commit 12 | # Amend the most recent local commit: 13 | alias gam='git commit --amend -m' # Only change commit message (optionally 'git add' files) 14 | alias gama='git commit --amend -am' # Add all modified files and change commit message 15 | alias gan='git commit --amend --no-edit' # Keep commit message (optionally 'git add' files) 16 | alias gana='git commit --amend --no-edit -a' # Add all modified files, but keep commit message 17 | 18 | alias gc='git commit --verbose' 19 | alias gcam='git commit -am' 20 | alias gcame='git commit --allow-empty-message -am ""' 21 | alias gcamg='git commit --gpg-sign -am' 22 | alias gcams='git commit --signoff -am' 23 | alias gcamu='git commit -am "Update"' 24 | alias gcem='git commit --allow-empty -m' 25 | alias gcm='git commit -m' 26 | alias gcmg='git commit --gpg-sign -m' 27 | alias gcms='git commit --signoff -m' 28 | 29 | # git add & commit 30 | alias gac='git add -A && git commit' 31 | 32 | # git branch 33 | alias gb='git branch' 34 | alias gba='git branch --all' 35 | alias gbd='git branch --delete' 36 | alias gbD='git branch -D' 37 | alias gbls='git branch --list | cat' 38 | 39 | # git bisect 40 | alias gbs='git bisect' 41 | alias gbsb='git bisect bad' 42 | alias gbsg='git bisect good' 43 | alias gbsr='git bisect reset' 44 | alias gbss='git bisect start' 45 | 46 | # git config 47 | alias gcf='git config' 48 | alias gcfl='git config --list' 49 | alias gcfls='git config --list | cat' 50 | 51 | # git clone 52 | alias gcl='git clone --recurse-submodules' 53 | 54 | # git checkout 55 | alias gco='git checkout' 56 | alias gcob='git checkout -b' 57 | alias gcobb='git checkout -' # "checkout branch before" 58 | 59 | # git cherry-pick 60 | alias gcp='git cherry-pick' 61 | alias gcpa='git cherry-pick --abort' 62 | alias gcpc='git cherry-pick --continue' 63 | 64 | # git diff 65 | alias gd='git diff' 66 | alias gds='git diff --staged' 67 | # Show the diff between latest stash and local working tree: 68 | alias gdst='git diff stash@{0}' # = git stash show -l 69 | # Show the diff between latest stash and HEAD: 70 | alias gdsth='git diff stash@{0} HEAD' 71 | # Show the diff between latest stash and its original parent commit: 72 | alias gdstp='git diff stash@{0}^ stash@{0}' # = git stash show -p 73 | 74 | # git fetch 75 | alias gf='git fetch' 76 | alias gfo='git fetch origin' 77 | 78 | # git log 79 | # Best default 'git log': 80 | alias gl='glog --name-status' 81 | # Fancy 'git log --graph': 82 | alias glg='glog --graph' 83 | # git graph branch: 84 | alias glgb='git log --graph --all --simplify-by-decoration --date=format:"%d/%m/%y" --pretty=format:"%C(yellow)%h%Creset%x09%C(bold green)%D%Creset%n%C(white)%ad%Creset%x09%C(bold)%s%Creset%n"' 85 | # Fancy 'git log --graph --oneline': 86 | alias glgo='git log --graph --date=format:"%d/%m/%y" --pretty=format:"%C(yellow)%h%Creset %C(white)%ad%Creset %C(bold)%s %C(bold green)%D%Creset%n"' 87 | # Fancy 'git log --graph --stat': 88 | alias glgs='glog --graph --stat' 89 | # Fancy 'git log --oneline': 90 | alias glo='git log --date=format:"%d/%m/%y" --pretty=format:"%C(yellow)%h%Creset %C(white)%ad%Creset %C(bold)%s %C(bold green)%D%Creset"' 91 | # Regular 'git log' in style: 92 | alias glog='git log --date=format:"%A %B %d %Y at %H:%M" --pretty=format:"%C(yellow)%H%Creset%x09%C(bold green)%D%Creset%n%<|(40)%C(white)%ad%x09%an%Creset%n%n %C(bold)%s%Creset%n%w(0,4,4)%n%-b%n"' # %w(0,4,4): no line-wrap, indent first line 4 chars, subsequent lines also 4 lines 93 | alias glr='glog --reverse --name-status' 94 | alias gls='git ls-files' 95 | 96 | # git merge 97 | alias gm='git merge' 98 | alias gmom='git merge origin/$(git_main_branch)' 99 | alias gmum='git merge upstream/$(git_main_branch)' 100 | 101 | # git mv 102 | alias gmv='git mv' 103 | 104 | # git push 105 | alias gp='git push' 106 | alias gpd='git push --delete' 107 | alias gpdo='git push --delete origin' 108 | alias gpf='git push --force-with-lease' 109 | alias gpt='git push && git push --tags' 110 | 111 | # git pull 112 | alias gpl='git pull' 113 | alias gplr='git pull --rebase' 114 | alias gplrs='git pull --recurse-submodules' 115 | 116 | # git reset 117 | # `grhard` is intentionally more verbose because `--hard` is unsafe; 118 | # there is no way to recover uncommitted changes. 119 | # In general the `--keep` flag is preferable. It will do exactly the same, 120 | # but abort if a file has uncommitted changes. 121 | # Having to type 'grhard' in full will make us think twice 122 | # about whether we REALLY want to get rid of all dirty files. 123 | alias grs='git reset --mixed' # Keep changes, but unstage them (`--mixed` = default behaviour) 124 | alias grshard='git reset --hard' # Remove changes, including anything uncommitted (Dangerous!) 125 | alias grsk='git reset --keep' # Safer version of `--hard`: reset is aborted if a file is dirty 126 | alias grss='git reset --soft' # Keep changes, and keep them staged 127 | 128 | # git rebase 129 | alias grb='git rebase' 130 | alias grbm='git rebase $(git_main_branch)' 131 | 132 | # git remote 133 | alias gr='git remote' 134 | alias gra='git remote add' 135 | alias grr='git remote rm' 136 | alias grsu='git remote set-url' 137 | alias grsh='git remote show' 138 | alias grv='git remote -v' 139 | 140 | # git reflow 141 | alias grl='git reflog' # Useful to restore lost commits after reset 142 | 143 | # git rm 144 | alias grm='git rm' 145 | 146 | # git status 147 | alias gs='git status' 148 | alias gsh='git show --date=format:"%A %B %d %Y at %H:%M" --pretty=format:"%C(yellow)%H%Creset%x09%C(bold green)%D%Creset%n%<|(40)%C(white)%ad%x09%an%Creset%n%n %C(bold)%s%Creset%n%w(0,4,4)%+b%n"' 149 | 150 | # git stash 151 | alias gst='git stash' # = git stash push 152 | alias gsta='git stash apply' 153 | alias gstd='git stash drop' 154 | alias gstl='git stash list' 155 | alias gstls='git stash list | cat' 156 | alias gstm='git stash -m' 157 | alias gstp='git stash pop' 158 | # Show the diff between latest stash and local working tree: 159 | alias gstsl='git stash show -l' # = git diff stash@{0} 160 | # Show the diff between latest stash and its original parent commit: 161 | alias gstsp='git stash show -p' # = git diff stash@{0}^! = git diff stash@{0}^ stash@{0} 162 | 163 | # git submodule 164 | alias gsub='git submodule' 165 | alias gsuba='git submodule add' 166 | alias gsubi='git submodule update --init' # Initialize submodules 167 | alias gsubpl='git submodule foreach git pull' 168 | alias gsubs='git submodule status' 169 | alias gsubu='git submodule update --remote --merge' # Update submodules 170 | 171 | # git switch 172 | alias gsw='git switch' 173 | alias gswc='git switch -c' 174 | 175 | # git tag 176 | alias gt='git tag' 177 | alias gtam='git tag -am' # <- takes message before annotated tag name: e.g. gtam 'Release v1.0.0' v1.0.0 178 | alias gtsm='git tag -sm' # GPG sign an annotated tag 179 | alias gtd='git tag --delete' 180 | alias gtl='git tag --list' 181 | alias gtls='git tag --list | cat' 182 | 183 | # git update-index 184 | # Ignore already tracked files: 185 | alias gignore='git update-index --skip-worktree' 186 | alias gunignore='git update-index --no-skip-worktree' 187 | alias gignored='git ls-files -v | grep ^S' 188 | 189 | alias gwch='git whatchanged -p --date=format:"%A %B %d %Y at %H:%M" --pretty=format:"%n%n%C(yellow)%H%Creset%x09%C(bold green)%D%Creset%n%<|(40)%C(white)%ad%x09%an%Creset%n%n %C(bold)%s%Creset%n%w(0,4,4)%+b%n"' 190 | 191 | # 192 | # Functions 193 | # 194 | 195 | # Check if main exists and use instead of master: 196 | function git_main_branch() { 197 | if [[ -n "$(git branch --list main)" ]]; then 198 | # -n: True if length of string output is non-zero 199 | echo main 200 | else 201 | echo master 202 | fi 203 | } 204 | --------------------------------------------------------------------------------