e.g. committing the staged changes would involve just "cc". Rewording the last commit is "cw", amending is "ce", and fixing up earlier commits is "cf".
Checking out a new branch is "bc", whereas creating a new branch is "bn".
Fetching to the default origin is "ff", likewise pushing is "pp".
But aside from the keymap being very terse, it's also highly discoverable. You're shown all the git commands, and before invoking a command, all the options for that command.
https://jdsalaro.com/note/wrist-friendly-git-shortcuts
I decided against git aliases in favour of shell aliases, but people might still find them interesting.
For me, and my wrists, gs and gf have been game-changing.
# show the last 10 branches I used
lb = !git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | awk -F' ~ HEAD@{' '{printf(\" \\033[33m%s: \\033[37m %s\\033[0m\\n\", substr($2, 1, length($2)-1), $1)}'
# checkout the previous branch I was using
cop = !git checkout --recurse-submodules $(git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | grep -v $(git branch --show-current) | head -1 | cut -d' ' -f1)
```
function w
#set --local staged (gs | cut -c1 | ag -v "\?" | string collect | string trim)
set --local staged (git status -s | grep "^[MADRCU]" | string collect | string trim)
if test -n "$staged"
#echo "something staged"
else
#echo "nothing staged"
git add .
end
if not string length -q -- "$argv"
gc -m 'WIP' -n
else
gc -m "$argv" -n
end
end```
Lifesaver and timesaver.
I have one called `b` that creates a new branch and commits.
One called `poop` that pushes the current branch to GitHub and create a PR.
etc etc
# Prettier logs:
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
ll = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative -20
l1 = log --pretty=oneline --abbrev-commit --decorate
# Show (all) (cached) diffs in Beyond Compare:
da = !sh diffall.sh
dac = !sh diffall.sh --cached
dt = difftool
dtc = difftool --cached
# Short status:
st = status -sb
ss = "!showci () { rev=${1:-HEAD}; git da $rev~1 $rev; }; showci $1"
gc - commit
gc! - amend
gcm - checkout master
gco - checkout
gcb - checkout new branch
Rebase:
grb
grbc - continue
grba - abort
Cherry pick:
gcp
gcpc - continue
gcpa - abort
These all are included in zsh git aliases but listed these I'm using on regular basis.
I also have a function that checks out master, pulls it, runs DB migrations and so on.
For longer ones like `g reset --soft HEAD~1` where I cba setting up alias, I just ctrl+r and fetch them with fzf or zsh autosuggestions - probably same amount of keystrokes as typing out alias
[2] git-push-set-upstream - Push current branch to remote
And plenty moreā¦
[1] https://github.com/benwinding/dotfiles/blob/master/bin/githu...
[2] https://github.com/benwinding/dotfiles/blob/2239e56df2a49818...
alias my_alias="command"
Add it to your ~/.bash_profile or ~/.zprofile so it's ready whenever you are. Check out this page for more info: https://linuxize.com/post/how-to-create-bash-aliases/
https://gitlab.com/halcanary/config/-/blob/master/git_config...
[alias]
justdoit = commit --amend --no-edit
I feel like every other commit I forget something, so a `git j[alias] g = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
[alias]
unstash = stash pop
because I was used to perforce nomenclature. It's also a quick autocomplete since it's my only u... command.
alias.co checkout
alias.br branch
alias.ci commit
alias.st status
alias.cm commit -m
alias.unstage reset HEAD --
alias.cob checkout -b
alias.pp pull --prune
asquash = git rebase -i master --autosquash
abs = git absorb -b HEAD~20
everything else is handled by vim-fugitive
git checkout -
returns you to the previous branch
(same for cd, "cd -" returns you to previous dir)