Last active
June 11, 2024 11:54
-
-
Save tometchy/53a5f6c30830f1f58875dbc0a62eb81c to your computer and use it in GitHub Desktop.
The Best Git aliases to put in your .gitconfig file - Git alias I use the most is snapshot, which can even take argument (description).
This file contains 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
# Download free cheatsheets and other materials from https://DevOps.Broker/free-materials | |
# | |
# Put this file in your home directory: ~/.gitconfig.aliases | |
# | |
# Include this in your own .gitconfig by using the | |
# [include] directive with the path to this file | |
# | |
# [include] | |
# path = ~/.gitconfig.aliases | |
# | |
# If you don't have any existing includes, you can add this via the following command | |
# | |
# git config --global include.path ~/.gitconfig.aliases | |
# | |
# Feel free to PR your favourite aliases to this file and of course give it a star if you like it :) | |
[alias] | |
lg = log --pretty=format:'%C(yellow)%h %C(bold green)(%ar)%C(reset) %C(reset)%>(12)%ad %C(green)%<(7)%aN%C(yellow)%d %C(reset)%s' | |
current = rev-parse --abbrev-ref HEAD | |
behind-remote-log = !CURRENT=$(git current) && git lg HEAD..origin/$CURRENT | |
behind-remote-log-verbose = "!f() { echo \"Commits added in remote:\"; git behind-remote-log; }; f" | |
ahead-remote-log = !CURRENT=$(git current) && git lg origin/$CURRENT..HEAD | |
ahead-remote-log-verbose = "!f() { echo \"Commits not pushed to remote:\"; git ahead-remote-log; }; f" | |
st = status | |
sta = !git behind-remote-log-verbose && git status && git ahead-remote-log-verbose # Note that this alias requires aliases above | |
sts = status --short | |
stsa = !git behind-remote-log-verbose && git status --short && git ahead-remote-log-verbose # Note that this alias requires aliases above | |
cnf = config --global -e | |
conf = cnf | |
d = diff | |
dcw = diff --color-words | |
ds = diff --staged | |
dscw = diff --staged --color-words | |
dt = difftool | |
dty = difftool -y | |
dts = difftool --staged | |
dtsy = difftool --staged -y | |
vd = difftool --tool=vimdiff | |
vdy = difftool --tool=vimdiff -y | |
vds = difftool --tool=vimdiff --staged | |
vdsy = difftool --tool=vimdiff --staged -y | |
p = push | |
pfl = push --force-with-lease | |
wip = !git add --all && git commit -m "WIP" | |
unwip = reset --soft HEAD^ | |
san = snapshot | |
snapshot = "!f() { git add --all; git commit -m \"SNAPSHOT_$(date +'%Y-%m-%d_%H-%M-%S') ${1}\" --allow-empty; git reset --soft HEAD^; git status --short; }; f" | |
show-snapshot = "!f() { git log --walk-reflogs --grep=\"SNAPSHOT\" -p ${1}; }; f" | |
hard-undo-all = !git clean -df && git reset --hard | |
co = commit | |
cov = commit -v | |
com = commit -m | |
coa = commit --amend | |
coane = commit --amend --no-edit | |
a = add | |
aa = add -A | |
aap = add -A -p | |
ai = add -i | |
r = reset | |
rs = reset --soft | |
rei = rebase -i | |
rec = rebase --continue | |
pur = pull --rebase | |
mt = mergetool | |
c = clean | |
cp = cherry-pick | |
cpc = cherry-pick --continue | |
show-assumed-unchanged = !git ls-files -v | grep "^[[:lower:]]" | |
tst=st |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment