Skip to content

Instantly share code, notes, and snippets.

@ivangabriele
Last active May 31, 2022 20:06
Show Gist options
  • Save ivangabriele/d0aa3cfb7382b0dc2393501b07ac7903 to your computer and use it in GitHub Desktop.
Save ivangabriele/d0aa3cfb7382b0dc2393501b07ac7903 to your computer and use it in GitHub Desktop.
Awesome Git Config.

Add those to you ~/.gitconfig (or %HOMEPATH%/.gitconfig under Windows):

[advice]
	skippedCherryPicks = false
	useCoreFSMonitorConfig = false

[alias]
	# Common aliases:
	br = branch
	ci = commit
	co = checkout
	st = status

	# Common branches aliases:
	dev = "!git co dev && git fp"
	d = dev
	main = "!git co main && git branch --set-upstream-to=origin/main main && git fp"
	m = main

	# Align the current forked project main branch with the original main one:
	align = "!git as && git M && git fetch -p upstream && git reset --hard upstream/main"

	# Add current diffs and stash them:
	add-stash = "!git add . && git stash"
	as = add-stash

	# Delete all non-main local branches:
	clean-branches = "!git br | grep -v "main" | grep -v "dev" | xargs git br -D"
	cb = clean-branches

	# Delete all main-merged local branches:
	clean-branches-only-merged = "!git M && git fp && git br --merged | grep -v '\\*' | xargs -n 1 git br -d"
	cbom = clean-branches-only-merged

	dump = cat-file -p

	# Edit last commit with the new diffs:
	fix = "!git add . && git commit --amend --no-edit --no-verify"
	# Same with a force-push to the remote matching branch to Heroku:
	fixh = "!git add . && git commit --amend --no-edit --no-verify && git push heroku HEAD:main -f"
	# Same with a force-push to the remote matching branch:
	fixp = "!git add . && git commit --amend --no-edit --no-verify && git push origin HEAD -f"

	# Fetch remote (locally removing remote deleted branches) and pull remote
	# into current branch:
	fetch-pull = "!git fetch -p && git pull"
	fp = fetch-pull

	# Print a pretty log:
	hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

	# Migrate master branch to main one after remote renaming:
	mm = "!git branch -m master main && git fetch origin && git branch -u origin/main main && git remote set-head origin -a && git remote prune origin"

	# Force-push current branch:
	push-head = push origin HEAD
	ph = push-head

	# Force-push current branch:
	push-force = push origin HEAD -f
	pf = push-force

	# Pop last stashed diffs and reset their tracking:
	stash-pop = "!git stash pop && git reset"
	sp = stash-pop

	# Show current HEAD tags:
	tag-info = tag --points-at HEAD
	ti = tag-info

	type = cat-file -t

	# Force Git to include execution rights diff under Windows OS:
	x = update-index --chmod=+x

[commit]
	gpgsign = true

[core]
	autocrlf = false
	excludesFile = ~/.gitignore

[init]
	defaultBranch = main

[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true

You can then use them as asliases: git br, git fix, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment