Skip to content

Instantly share code, notes, and snippets.

@jnials
Forked from 0livare/.gitconfig
Created November 25, 2020 14:37
Show Gist options
  • Save jnials/9c901f1840e3039a7f065deb61a99886 to your computer and use it in GitHub Desktop.
Save jnials/9c901f1840e3039a7f065deb61a99886 to your computer and use it in GitHub Desktop.
My git alias list. Running 'git alias' will pretty-print these commands to the terminal.
[user]
name = Zach Posten
email = zach@posten.io
[push]
default = upstream
[pull]
ff=only
[core]
autocrlf = input
[alias]
# === Common Commands ===
s = status # Shortcut for status
b = branch # Shortcut for branch
a = add # Shortcut for add
d = difftool # Shortcut for difftool
m = mergetool # Shortcut for mergetool
f = fetch --all --prune
po = push origin # Shortcut for push origin
pu = push upstream # Shortcut for push upstream
cp = cherry-pick # Shortcut for cherry-pick
cpcont = cherry-pick --continue# Shortcut for cherry-pick --continue
rh = reset --hard # Shortcut for reset hard
r = rebase # Shortcut for rebase
rcont = rebase --continue # Shortcut for rebase --continue
ra = rebase --abort # Shortcut for rebase --abort
rem = remote # Shortcut for remote
pr = remote prune # Shortcut for remote prune
prune = remote prune # Shortcut for remote prune
rd = range-diff # Shortcut for range-diff
# === Assorted ===
stu = !git stash show -p | git apply -R # Stash un-apply
alias = "!grep -E '( =|^$)' ~/.gitconfig | sed -E -e 's/=.+#//' | less" # List formatted aliases and descriptions
al2 = "!git config -l" | grep alias | cut -c 7- # List aliases with expanded commands
mff = merge --ff-only # Shortcut for merge ff only
mnf = merge --no-ff # Shortcut for merge no ff
rmh = remote set-head origin -d # Remove origin/HEAD
ignore = !git rm -r --cached . && git add . # Fix untracked files, commit all changes first
orig = !find -name "*.orig" -delete # Delete all files ending in ".orig"
hide = update-index --skip-worktree # Keep a certain file from appearing in diffs
unhide = update-index --no-skip-worktree # Allow a hidden file to again appear in diffs
# === File Management ===
un = reset HEAD # More logical name for reset HEAD
disc = checkout -- # Reverts a path to the last committed state
co = checkout # Shortcut for checkout
cob = checkout -b # Create a new branch and then switch to the newly created branch
# === Commit Commands ===
cm = commit # Shortcut for commit
com = commit -m # Commit with in-line message
cam = commit -am # Stage all tracked and untracked files and then commit with in-line message
amend = commit --amend # Add staged files to the previous commit. Changes the SHA-1 of the previous commit
fix = commit --amend --no-edit # Amend the previous commit with all current changes keeping the previous commit message
tmp = commit -m 'WIP - incremental commit' # Quick command for saving work progress which will be modified later
# === Working with Previous Commit Commands ===
r1 = reset HEAD^ # Move HEAD pointer back one commit and keep all changes in the working directory
r2 = reset HEAD^^ # Move HEAD pointer back two commits and keep all changes in the working directory
f1 = reset HEAD@{1} # Move HEAD pointer forward one commit
d1 = difftool HEAD^ HEAD # Diff a file with itself from the previous commit
d2 = difftool HEAD^^ HEAD # Diff a file with itself from two commits ago
doc = ! /c/batch/diffOneCommit.bat # Get the diff of a single commit ("diff one commit")
dh = remote set-head origin -d
dname = diff --name-only # Show the names of all files changed between two commits. Usage: "git dname SHA1 SHA2"
# === Branch management ===
dbr = push origin --delete # Delete branch remote
parseBranchName = !git branch | grep '*' | sed 's/* //' # Get the current branch name
publish = !git parseBranchName | xargs git po -u # Create a copy of the current branch on origin
pushup = !git branch | grep '*' | sed 's/* /head:zp\\//' | xargs git push up -u # Create current branch on remote 'up' with prefix 'zp/'
delup = !git branch | grep '*' | sed 's/* /zp\\//' | xargs git push up --delete # Delete the remote branch matching 'zp/<current-branch>'
del = branch -D # Delete local branch
master = !git move master up/master
dev = !git move dev up/develop
move = branch -f
# === Logging ===
last = log -1 --decorate # Show the last commit on the current branch
# Possible colors: normal, black, red, green, yellow, blue, magenta, cyan, white
# Possible modifiers: bold (neon), dim, ul, blink, reverse
# Common placeholders: %C()-change color, %h-short commit hash, %d-ref names, %cn-committer name, %ar-relative date
lsb = log --pretty=format:"%C(auto)%h%d\\ %s\\ %C(cyan)[%aN]" --graph # List commits on this branch, formatted
lsd = log --pretty=format:"%C(auto)%h%d\\ %s\\ %C(cyan)[%aN]\\ %C(magenta)[%ad]" --graph --all -20 # List commits including date
lsa = !git lsb --all # List all commits
ls = !git lsa -20 # List last 20 commits
lsfa = !git lsa --numstat # List all commits and their changed files
lsf = !git lsfa -10 # List last 10 commits and their changed files
local-branch-dates = !git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
remote-branch-dates = !sh /c/batch/git-branches-by-commit-date.sh
lm = log --pretty=%B -1 # Print out the entirety of the previous log message, pipe to pbcopy for copying to clipboard.
# === Windows helpers ===
xp = !explorer . # Opens Windows Explorer to the current directory
op = !start # Starts the default editor for the specified file
cmd = !sh -c 'start' # Starts Windows Command Prompt to the current directory
# === TortoiseGit helpers ===
tlog = !sh -c 'tortoisegitproc /command:log' # Launches TortoiseGit Log
tls = !git tlog # Also launches TortoiseGit Log
tcmt = !sh -c 'tortoisegitproc /command:commit' # Launches TortoiseGit Commit
tst = !sh -c 'tortoisegitproc /command:repostatus' # Launches TortoiseGit Check For Modifications
tgr = !sh -c 'tortoisegitproc /command:revisiongraph' # Launches TortoiseGit Revision Graph
# === URL generation ===
rrl = !sh -c 'echo $(git config remote.${1:-origin}.url | sed -E s/[a-z]+@\\(.+?\\):\\(.+\\)\\.git$/\\\\\\1\\\\\\/\\\\\\2/)' - # Get the URL of a repository (origin by default)
crl = !sh -c 'echo $(git rrl)"/commit/"$(echo $(git rev-parse $([ "$0" = "sh" ] && echo HEAD || echo $0)))' # 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/"$(git config branch.$BRANCH.merge | sed -E s/refs.heads.//)' - # Get the GitHub URL of a branch (HEAD by default)
# == Web launching ===
hb = !sh -c 'git web--browse $(git rrl ${1})' - # Launches a web browser for a remote repository (origin by default)
chb = !sh -c 'git web--browse $(git crl ${1})' - # Launches a web browser for a specific commit (HEAD by default)
bhb = !sh -c 'git web--browse $(git brl ${1})' - # Launches a web browser for a specific branch (HEAD by default)
# == Proxy ===
setproxy = !git config --global http.proxy http://10.10.5.18:8080 && git config --global https.proxy https://10.10.5.18:8080 && npm config set proxy http://10.10.5.18:8080 && npm config set https-proxy http://10.10.5.18:8080
rmvproxy = !git config --global --unset http.proxy && git config --global --unset https.proxy && npm config rm proxy && npm config rm https-proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment