Skip to content

Instantly share code, notes, and snippets.

@albannurkollari
Last active December 12, 2023 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albannurkollari/36e30896e4247a0c55c1cfae3ed4a05b to your computer and use it in GitHub Desktop.
Save albannurkollari/36e30896e4247a0c55c1cfae3ed4a05b to your computer and use it in GitHub Desktop.
My go-to .gitconfig
[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 <alban.nurkollari@ingka.com>' --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 git@github.com-$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
[user]
name = Alban Nurkollari
email = albannurkollari@gmail.com
[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 "git@github.com:"]
insteadOf = git://github.com/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment