Created
July 29, 2020 19:51
-
-
Save borkweb/694184a33342a48be48e576bdfe0fc9f to your computer and use it in GitHub Desktop.
My aliases for git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
# === Common Commands === | |
a = add # Shortcut for add | |
br = branch # Shortcut for br | |
branches = branch -a # Shortcut for branch -a | |
co = checkout # Shortcut for checkout | |
cob = checkout -b # Shortcut for checkout -b | |
cp = cherry-pick # Shortcut for cherry-pick | |
po = push origin # Shortcut for push origin | |
remotes = remote -v # Shortcut for remote -v | |
st = status # Shortcut for status | |
stashes = stash list # Shortcut for stash list | |
sub = submodule # Shortcut for submodule | |
tags = tag # Shortcut for tag | |
# === File Management Commands === | |
discard = checkout -- # Reverts a path to the last committed state. | |
undo = checkout -- # Reverts a path to the last committed state. | |
unstage = reset -q HEAD -- # Unstage a path | |
# === Commit Commands === | |
amend = commit --amend # Add staged files to the previous commit. Changes the SHA-1 of the previous commit. | |
ca = commit -av # Shortcut for commit -av (verbose commit with diff) | |
ci = commit -v # Shortcut for commit -v (verbose commit with diff) | |
fix = commit --amend --no-edit # Amend the previous commit with all current changes keeping the previous commit message. | |
uncommit = reset --mixed HEAD~ # Undoes a commit while retaining file changes. | |
# === Branch Management === | |
current = "!git branch | grep '*' | sed 's/* //'" # Gets the current branch name. | |
publish = "!f() { git push -u ${1:-origin} $(git rev-parse --abbrev-ref HEAD); }; f" # Create a copy of the current branch on origin. | |
remote-br = "!f() { git ls-remote --heads ${1:-origin} | sed 's?.*refs/heads/??'; }; f " # Print all remote branches. Defaults to the origin branch but a different one can be specified. | |
# === Diffing & Change Info === | |
df = "!f() { [ -z \"$GIT_PREFIX\" ] || cd \"$GIT_PREFIX\" && git diff --color \"$@\" | diff-so-fancy | less --tabs=4 -RFX; }; f" # Fancy diff using https://github.com/so-fancy/diff-so-fancy | |
dfs = df --staged # Diff staged files | |
dfc = "!dfc() { git df $1^ $1; }; dfc" # Get changes for a single commit | |
dt = difftool # Open up diff in vimdiff | |
mt = mergetool # Open up merge conflict in vimdiff | |
# === Logging === | |
l = log --pretty=format:"%C(auto)%h%d\\ %s\\ %C(cyan)[%aN,\\ %Creset%cr%C(cyan)]" --graph # List commits on this branch, formatted | |
last = log -1 --decorate # Show the last commit on the current branch | |
ld = log --pretty=format:"%C(auto)%h%d\\ %s\\ %C(cyan)[%aN,\\ %Creset%cr%C(cyan)]\\ %C(magenta)[%ad]" --graph --all -20 # List commits including date | |
la = !git l --all # List all commits | |
ls = !git la -20 # List last 20 commits | |
lsac = !git la --numstat # List all commits and their changed files | |
lsc = !git lsac -10 # List last 10 commits and their changed files | |
# === GitHub Commands === | |
issues = !gh issue list # Get a list of issues from GitHub. | |
url = "!f() { gh repo view --web; }; f" # Open the current repo in the web browser. | |
rrl = !sh -c 'URL=$(git config remote.${1:-origin}.url | sed -E s/[a-z]+@\\(.+?\\):\\(.+\\)\\.git$/\\\\\\1\\\\\\/\\\\\\2/) && echo "https://$URL"' - # Get the URL of a repository (origin by default) | |
crl = !sh -c 'URL=$(git rrl)"/commit/"$(echo $(git rev-parse $([ "$0" = "sh" ] && echo HEAD || echo $0))) && echo "$URL"' # Get the GitHub URL of the revision (HEAD by default) | |
brl = !sh -c 'BRANCH=${1:-$(git symbolic-ref --short HEAD)} && echo $(git rrl $(git config branch.$BRANCH.remote))"/tree/"$BRANCH' - # Get the GitHub URL of a branch (HEAD by default) | |
open-rrl = !xdg-open $(git rrl) # Open rrl in a browser. | |
open-crl = !xdg-open $(git crl) # Open crl in a browser. | |
open-brl = !xdg-open $(git brl) # Open brl in a browser. | |
prc = "!gh pr create --label 'code review'" --web # Create a PR | |
prd = "!gh pr create --draft --label 'code review'" # Create a draft PR | |
# === Assorted Commands === | |
aliases = "!grep -E '( =|^$)' ~/.gitconfig | sed -E -e 's/^([^=]+)=.+#([^#]+)$/\\x1b[96m\\1\\x1b[0m\\x1b[32m\\2\\x1b[0m/'" # List formatted aliases and descriptions | |
aliases2 = "!git config -l | grep alias | cut -c 7-" # List aliases with expanded commands | |
cmd = "!git aliases" # Alias for git aliases | |
commands = "!git aliases" # Alias for git aliases | |
sub = submodule update --init --recursive # Update submodules recursively |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment