Skip to content

Instantly share code, notes, and snippets.

@jean-leonco
Created March 14, 2026 15:10
Show Gist options
  • Select an option

  • Save jean-leonco/65b314dab8a2151a7a21a73c6880e2d9 to your computer and use it in GitHub Desktop.

Select an option

Save jean-leonco/65b314dab8a2151a7a21a73c6880e2d9 to your computer and use it in GitHub Desktop.
Git config with alias
[alias]
# commit
ci = commit
# checkout to branch
co = checkout
# checkout to a new branch
cb = checkout -b
# short format status with branch
st = status -sb
# unstage all changes
unstage = reset HEAD --
# rollback commit
rb = reset --soft HEAD~1
# delete branch
delete = branch -d
# rename branch
rename = branch -m
# Show branches than can be deleted https://stackoverflow.com/a/56026209
dry-cleanup="!git checkout -q main && git for-each-ref refs/heads/ \"--format=%(refname:short)\" | while read branch; do mergeBase=$(git merge-base main $branch) && [[ $(git cherry main $(git commit-tree $(git rev-parse \"$branch^{tree}\") -p $mergeBase -m _)) == "-"* ]] && echo \"$branch is merged into main and can be deleted\"; done"
# Delete merged branches https://stackoverflow.com/a/56026209
cleanup="!git checkout -q main && git for-each-ref refs/heads/ \"--format=%(refname:short)\" | while read branch; do mergeBase=$(git merge-base main $branch) && [[ $(git cherry main $(git commit-tree $(git rev-parse \"$branch^{tree}\") -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done"
# `git log` with patches shown with difftastic.
dl = -c diff.external=difft log -p --ext-diff
# Show the most recent commit with difftastic.
ds = -c diff.external=difft show --ext-diff
# `git diff` with difftastic.
dft = -c diff.external=difft diff
# Pretty commit graph
lg = log --graph --oneline --decorate --all
# Quick amend
amend = commit --amend --no-edit
# Show last commit
last = log -1 HEAD
# Quick stash
save = stash push -m
# Quick WIP commit
wip = commit -am "wip"
# Contributor stats
contributors = shortlog -sn --all
# Quick switch to main
main = checkout main
# List all branches
branches = branch -a
# Soft undo
undo = reset --soft HEAD~1
[init]
defaultBranch = main
[pull]
ff = only
[push]
autoSetupRemote = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment