Skip to content

Instantly share code, notes, and snippets.

@mtik00
Last active July 13, 2023 15:21
Show Gist options
  • Save mtik00/61d13db6faf8f861a891531af272c101 to your computer and use it in GitHub Desktop.
Save mtik00/61d13db6faf8f861a891531af272c101 to your computer and use it in GitHub Desktop.
Quick and dirty setup for git and bash aliases.
#!/usr/bin/env bash
# Quick and dirty setup for git and bash aliases.
[ ! -f ~/.git-aliases ] && cat <<-END > ~/.git-aliases
alias g='git'
alias gd='git diff'
alias gf='git fetch --all --prune'
alias gfpr='git fetch --all --prune && git pull --rebase'
alias gg='git log --graph --pretty=format:'\''%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset'\'' --abbrev-commit --date=relative'
alias gh='cd "$(git rev-parse --show-toplevel)"'
alias gl='git log -1'
alias gll='git log --graph --pretty=oneline --abbrev-commit'
alias gpr='git pull --rebase'
alias gpristine='git reset --hard && git clean -dfx'
alias gs='git status'
alias gwc='git whatchanged'
END
grep .git-aliases ~/.bashrc || echo "source ~/.git-aliases" >> ~/.bashrc
git config --global --replace-all alias.co checkout
git config --global --replace-all alias.br branch
git config --global --replace-all alias.ci commit
git config --global --replace-all alias.st status
git config --global --replace-all alias.unstage 'reset HEAD --'
git config --global --replace-all alias.last 'log -1'
git config --global --replace-all alias.l 'log -1'
git config --global --replace-all alias.h '!git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative --color=always|head -n1'
git config --global --replace-all alias.undo 'reset HEAD~1'
git config --global --replace-all alias.aliases "config --get-regexp '^alias\\.'"
# in WSL2, run this to open the current repo in a web browser.
# git config --global alias.site '!explorer.exe $(echo `git config remote.origin.url` | sed "s,git@,https://," | sed "s,.com:,.com/," | sed -E '"'"'s|(https?://)(.*?@)?(.*)|\1\3|'"'"' | sed "s,.git\$,,") > /dev/null 2>&1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment