Skip to content

Instantly share code, notes, and snippets.

@NickPolyder
Last active November 25, 2024 08:55
Show Gist options
  • Save NickPolyder/33a66cd3abb5d54c891c575678fba642 to your computer and use it in GitHub Desktop.
Save NickPolyder/33a66cd3abb5d54c891c575678fba642 to your computer and use it in GitHub Desktop.
Git aliases for streamlined operations (insert on .gitconfig)
[diff]
tool = meld
guitool = meld
[difftool]
prompt = true
[merge]
tool = meld
guitool = meld
[mergetool]
prompt = true
[core]
editor = \"C:/Program Files/GitExtensions/GitExtensions.exe\" fileeditor
autocrlf = true
[alias]
s = status
co = checkout
cob = checkout -b
del = branch -D
br = branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate
save = !git add -A && git commit -m 'chore: savepoint'
undo = reset --soft HEAD~
delete = push origin --delete
pull-updates = "!f() { (git stash && git checkout $1 && git pull --rebase && git checkout $2 && git rebase $1 && git stash pop) }; f"
push-updates = "!f() { (git stash && git checkout $2 && git pull --rebase && git checkout $1 && git rebase $2 && git checkout $2 && git merge --no-ff $1 && git push origin $2 && git checkout $1 && git rebase $2 && git stash pop) }; f"
sync-updates = "!f() { (git stash && git checkout $1 && git pull --rebase && git checkout $2 && git rebase $1 && git push origin --force-with-lease && git stash pop) }; f"
pull-create = "!f() { (git stash && git checkout $1 && git pull --rebase && git checkout -B $2 && git stash pop) }; f"
temp-ignore = update-index --assume-unchanged
temp-unignore = update-index --no-assume-unchanged
branch-rename = branch -m
change-branch = "!f() { (git stash && git checkout $1 && git stash pop) }; f"
check-local-stale-refs = "!f() { (git remote prune $1 --dry-run) }; f"
remove-local-stale-refs = "!f() { (git remote prune $1) }; f"
pu = "!f() { (git checkout $1 && git pull --rebase && git checkout $2 && git rebase $1) }; f"
open = !explorer$(git config remote.origin.url)
browse = !git open
stash-unstaged = "!f() { (git commit --message WIP && git add --all && git stash push -u -k && git reset --soft HEAD^ && git restore -S *) }; f"
stash-unstaged-m = "!f() { (git commit --message WIP && git add --all && git stash push -m \\$1\\ -u -k && git reset --soft HEAD^ && git restore -S *) }; f"
stash-all = "!f() { (git stash push -u -k ) }; f"
stash-all-m = "!f() { (git stash push -m \\$1\\ -u -k ) }; f"
squash-updates = "!f() { LASTMERGE=`git merge-base $1 $2`; git rebase -i --autosquash --autostash $LASTMERGE; }; f"
push-local = "!f() { (CURRENTBRANCH=`git branch --show-current`; git push --recurse-submodules=check origin refs/heads/$CURRENTBRANCH:refs/heads/$1; git refresh $1) }; f"
refresh = "!f() { CURRENTBRANCH=`git branch --show-current`; (git stash && git checkout $1 && git pull --rebase && git stash pop); git checkout $CURRENTBRANCH; }; f"
commits-since = "!f() { git log --graph --since=$1; }; f"
last-commits = "!f() { git log --graph $1; }; f"
head-hash = "!f() { git log -1 --pretty=%H $1; }; f"
head-summary = "!f() { git log -1 --summary $1; }; f"
c-history = !git log --max-count=10 --pretty='%Cred %H %Creset, Author: %an, %ar:%n%s%n'
track = "!f() { git branch --set-upstream-to $1; }; f"
untrack = branch --unset-upstream
whoami = status -b --porcelain
log-between = !sh -c 'git log $1..$2 --format=oneline$@'
[i18n]
filesEncoding = utf-8
[pull]
rebase = true
[fetch]
prune = true
[rebase]
autoStash = true
autosquash = false
updateRefs = false
[difftool "meld"]
path = C:/Program Files (x86)/Meld/meld.exe
cmd = \"C:/Program Files (x86)/Meld/meld.exe\" \"$LOCAL\" \"$REMOTE\"
[mergetool "meld"]
path = C:/Program Files (x86)/Meld/meld.exe
cmd = \"C:/Program Files (x86)/Meld/meld.exe\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" --output \"$MERGED\"
[rerere]
enabled = true
[init]
defaultBranch = main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment