Last active
April 4, 2025 00:21
-
-
Save albannurkollari/36e30896e4247a0c55c1cfae3ed4a05b to your computer and use it in GitHub Desktop.
My go-to .gitconfig
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
[color] | |
ui = auto | |
[core] | |
editor = code --wait | |
autocrlf = false | |
[diff] | |
tool = code | |
[difftool "code"] | |
cmd = code --wait --diff $REMOTE $LOCAL | |
[alias] | |
# Info | |
br = branch --show-current | |
changes = log --oneline --shortstat main..HEAD | |
files-changed = "!f() {\ | |
base="${1:-main}";\ | |
git diff --diff-filter=ACMR --name-only $base...HEAD;\ | |
}; f" | |
fullLog = log --format=fuller | |
contributors = shortlog -sn --no-merges --email | |
authorbani = "!f() { git commit --amend --author='Alban Nurkollari <[email protected]>' --no-edit; }; f" | |
cane = commit --amend --no-edit | |
master = "!f() { git checkout master && git pull; }; f" | |
main = "!f() { git checkout main && git pull; }; f" | |
pushfirst = "!f() { git branch --show-current | xargs git push --set-upstream origin; }; f" | |
prco = "!f() { git fetch origin pull/$1/head:$2 && git checkout $2; }; f" | |
pullr = pull --rebase | |
s = status -s -b | |
sl = status -vv | |
sa = status -vv --ignored | |
d = diff | |
dc = diff --cached | |
dl = diff --find-copies-harder | |
ll = log --graph --format=format:"'%C(bold blue)%h %C(auto)%d %C(reset) - %s %n %C(dim white)%an (%cd; %cr)'" | |
la = log --graph --format=format:"'%C(bold blue)%h %C(auto)%d %C(reset) - %s %n %C(dim white)%an (%cd; %cr)'" --branches | |
lr = log --graph --format=format:"'%C(bold blue)%h %C(auto)%d %C(reset) - %s %n %C(dim white)%an (%cd; %cr)'" --all | |
lol = log --oneline | |
# Moving around | |
co = checkout | |
cop = checkout @{-1} | |
# Adding changes | |
au = add -u . | |
## Branches | |
rebranch = "!f(){\ | |
old_branch=$(git branch --show-current);\ | |
git branch -m $1;\ | |
git push origin :$old_branch $1;\ | |
git branch -u origin/$1 $1;\ | |
}; f" | |
## Committing | |
c = commit | |
cs = commit -S | |
ca = commit --amend | |
cas = commit --amend -S | |
cae = commit --allow-empty | |
cn = commit --no-verify | |
canv = commit --amend --no-verify | |
cp = cherry-pick | |
cpa = cherry-pick --abort | |
cpc = cherry-pick --continue | |
cps = cherry-pick --skip | |
fix = "!f() { git commit --fixup $1; }; f" | |
cob = "!f() { git checkout origin/rel/fw-$1/maint -b $2; }; f" | |
corev = "!f() { git checkout -b $1 && git revset $2; }; f" | |
delb = "!f() { git branch -D $1; }; f" | |
delball = "!f() { git checkout main && git branch | grep -v main | xargs git branch -D; }; f" | |
pushf = push --force-with-lease | |
ma = merge --abort | |
mi = merge -i | |
mc = merge --continue | |
ra = rebase --abort | |
ri = rebase -i | |
rc = rebase --continue | |
rimas = rebase -i main --autosquash | |
ria = rebase -i --autosquash | |
rebm = rebase main | |
## Gerrit | |
revm = "!f() { git push origin HEAD:refs/for/$1; }; f" | |
revp = push origin HEAD:refs/for/master%private | |
revwip = push origin HEAD:refs/for/master%wip | |
revwipp = push origin HEAD:refs/for/master%wip%private | |
revd = push origin HEAD:refs/drafts/master | |
revhash = push origin HEAD:refs/for/master%t | |
revrel = "!f() { git push origin HEAD:refs/for/rel/fw-$1/maint; }; f" | |
rev = "!f() { git push origin HEAD:refs/for/$1; }; f" | |
revset = "!f() { git fetch origin $1 && git reset --hard FETCH_HEAD; }; f" | |
revsetm = "!f() { git fetch origin master && git reset --hard FETCH_HEAD; }; f" | |
set = reset --hard | |
setm = reset --hard master | |
prip = push origin HEAD:refs/for/master%private | |
wipp = push origin HEAD:refs/for/master%wip | |
## Stashing | |
store = stash -u | |
retrieve = stash pop | |
## Commit Message | |
hs = log --pretty='%C(yellow)%h %C(cyan)%cd 🔸%Cblue%aN, %Cgreen%cN🔹%C(auto)%d %Creset%s' --date=relative --date-order | |
getmsg = "!f() { git show -s --format=%B $1; }; f" | |
lastcommitmsg = log -1 --pretty=%B | |
getmultiplemsg = "!f() { git log -n $1; }; f" | |
## Print the difference between `master` branch and current HEAD and then apply it to a newly created branch. | |
pad = "!f() { git diff-index main --binary > $1.diff && git checkout main && git checkout -b $2 && git apply < $1.diff; }; f" | |
## Tagging | |
tagam = "!f() { git tag -a $1 -m $1 }; f" | |
## disecting/inspecting/searching | |
findkeyword = "!f() { git log -S $1 --oneline -- ':(exclude)*package-lock.json' . ; }; f" | |
logs = log --show-signature | |
## Find which commits have changed a given file | |
follow = "!f() { git hs --follow -- $1; }; f" | |
pruneall = "!f() { git gc --prune=now && git remote prune origin; }; f" | |
## core stuff | |
clnwithconfigkey = "!f() { git clone [email protected]$1:$2/$3.git; }; f" | |
setuserandname = "!f() { git config user.name \"$1\"; git config user.email $2; }; f" | |
deleteexistingref = "!f() { git push . :refs/original/refs/heads/$1; }; f" | |
cleanupoldrefs = "!f() { git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin; }; f" | |
conflictedfiles = diff --name-only --diff-filter=U | |
get-parent-branch = "!f() { \ | |
git for-each-ref --format \"%(refname:short)\" refs/heads/ | while read branch; do \ | |
if git merge-base --is-ancestor \"$branch\" HEAD; then \ | |
echo \"$branch\"; \ | |
break; \ | |
fi; \ | |
done; \ | |
}; f" | |
move-onto-parent = "!f() { \ | |
parent=${1:-$(git get-parent-branch)}; \ | |
git rebase --onto \"$parent\" HEAD~1 HEAD; \ | |
}; f" | |
last-commit-for-file = "!f() { \ | |
git log --follow --oneline -- \"$1\" | head -n 1; \ | |
}; f" | |
# Moves the last commit to the parent branch (or specified target) and rebases | |
move-fix = "!f() { \ | |
target_branch=\"${1:-$(git get-parent-branch)}\"; \ | |
if [ -z \"$target_branch\" ]; then \ | |
echo \"Error: Could not auto-detect parent branch. Specify manually.\"; \ | |
exit 1; \ | |
fi; \ | |
current_branch=$(git branch --show-current); \ | |
if [ \"$current_branch\" = \"$target_branch\" ]; then \ | |
echo \"Error: Current branch is the same as target branch.\"; \ | |
exit 1; \ | |
fi; \ | |
git rebase --onto \"$target_branch\" \"HEAD~1\" \"HEAD\"; \ | |
git branch -f \"$target_branch\" HEAD; \ | |
git checkout \"$current_branch\"; \ | |
git rebase \"$target_branch\"; \ | |
}; f" | |
[user] | |
name = Alban Nurkollari | |
email = [email protected] | |
signingkey = AB3AC4A1CB5D45CD | |
[winUpdater] | |
recentlySeenVersion = 2.25.0.windows.1 | |
[init] | |
defaultBranch = main | |
[commit] | |
gpgsign = true | |
[push] | |
followTags = true | |
autoSetupRemote = true | |
[url "https://github.com/"] | |
insteadOf = git://github.com/ | |
[url "[email protected]:"] | |
insteadOf = git://github.com/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment