Skip to content

Instantly share code, notes, and snippets.

@kuvaldini
Last active July 6, 2022 14:58
Show Gist options
  • Save kuvaldini/56ab6c2a1cf88745cc55b797099cf809 to your computer and use it in GitHub Desktop.
Save kuvaldini/56ab6c2a1cf88745cc55b797099cf809 to your computer and use it in GitHub Desktop.
Useful aliases for Git
[alias]
sta = status
bra = branch
co = checkout
cos = checkout --recurse-submodule
cosf = checkout --recurse-submodule --force
root = rev-parse --show-toplevel
toplevel = rev-parse --show-toplevel
current-branch = rev-parse --abbrev-ref HEAD
sub = submodule
sup = submodule update
## Push to all remotes
pushar = !git remote | xargs -I {} git push {}
## Push from remote to remote, ref must already be fetched
remote2remote = "!sh -c \"git push $2 refs/remotes/$1/*:refs/heads/*\""
update-branch = "!sh -c \"git update-ref refs/heads/$1 refs/remotes/origin/$1\""
remove-gone = "!env LANG=en_US git branch -vv | awk '/^[^*].*: gone]/{print $1}' | xargs git bra -d "
## Fetch pull-request from GitHub
fetch-pr = "! f(){ rem=$1;shift; n=$1;shift; git fetch -u $rem pull/$n/head:pr/$n pull/$n/merge:pr/merge/$n "$@"; }; f"
fetcho = fetch origin
## Pull pull-request from GitHub, i.e. fetch+merge
pull-pr = "! f(){ rem=$1;shift; n=$1;shift; git pull --rebase=false $rem pull/$n/head "$@"; }; f"
## REQUIRED Git 2.21 (Q1 2019)
nicelog = log --decorate --graph --oneline -11
l = log --graph --decorate --date=human --pretty=format:'%C(yellow bold)%h %C(green dim)%ad %C(blue)%an <%ae> %C(auto)%d %GS %n%w(0,3,3)%s%n%+b'
ll = log --graph --decorate --date=human --pretty=format:'%C(yellow bold)%H %C(auto)%d %GS %n%C(white dim)author: %C(green dim)%ai %C(blue)%an <%ae> %C(green)%ad %n%C(white dim)commiter: %C(green dim)%ci %C(blue)%cn <%ce> %C(green)%cd %n%w(0,3,3)%s%n%+b'
nl2 = log --graph --decorate --date=human --pretty=format:'%C(yellow bold)%h %C(green dim)%ad %C(blue)%an <%ae> %C(auto)%d %GS %n%w(0,3,3)%s'
nl = log --graph --decorate --date=human --pretty=format:'%C(yellow bold)%h %C(green dim)%ad %C(blue)%an %C(auto)%s %d'
## Third party
lc = log-compact --graph --decorate
fo = !git foresta --style=10 \"$@\" | less -RSX
fa = !git foresta --all --style=10 \"$@\" | less -RSX
#!/usr/bin/env bash
curl https://gist.githubusercontent.com/kuvaldini/56ab6c2a1cf88745cc55b797099cf809/raw/5716a8363a49818181221546dd343c987951c211/.alias.gitconfig >~/.alias.gitconfig
git config --global include.path '~/.alias.gitconfig'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment