Skip to content

Instantly share code, notes, and snippets.

@cfstras
Last active April 29, 2020 21:51
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 cfstras/fac9cd824cedab5cac14683d318e022c to your computer and use it in GitHub Desktop.
Save cfstras/fac9cd824cedab5cac14683d318e022c to your computer and use it in GitHub Desktop.
Git config helpers

Some config helpers for git

~/.gitconfig:

[alias]

# my lazyness
	git = !git # git git git checkout
	ad = add
	ada = add
	addd = add
	pushg = push
	psuh = push
	pushy = push
	fecth = fetch
	recomit = recommit
	rest = reset
	reet = reset
	cehckout = checkout
	comit = commit
	cehckotu = checkout
	poush = push
	checkotu = checkout
	chcekout = checkout
	pushj = push
	fpushg = fpush

# hotkeys
	ci = commit
	co = checkout
	br = branch
	st = status
	s = status

# small utilities
	fpush = push --force-with-lease
	hard = reset --hard
	cp = cherry-pick
	g = grep -i
	dc = diff --cached
	type = cat-file -t
	dump = cat-file -p
	# commit --amend, keep the message
	recommit = commit --amend -C HEAD

# more complex utilities
	# quick git log overview
	hist = log --abbrev-commit --pretty='format:%Cblue%h%Creset %s (%Cgreen%an%Creset)%Cred%d%Creset' --graph --notes --date=relative
#	hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
	# show file duplicates
	dupes = !git ls-tree -r HEAD | cut -c 13- | sort | uniq -D -w 40

	# show big files
	fatfiles = "!git rev-list --all --objects | \t\tsed -n $(git rev-list --objects --all | \t\tcut -f1 -d' ' | \t\tgit cat-file --batch-check | \t\tgrep blob | \t\tsort -n -k 3 | \t\ttail -n40 | \t\twhile read hash type size; \t\t\tdo echo -n \"-e s/$hash/$size/p \"; \t\tdone) | \t\tsort -n -k1"

	# Quick git server!
	# After starting, go to your colleague and type "git fetch git://my_hostname/"
	quickserve = daemon --verbose --export-all --base-path=.git --reuseaddr --strict-paths .git/

	recent = "!git recentlong | head -n10 | column -ts'|'"

	# cor = Checkout-recent. Needs fzf installed.
	pretty-branch = "!git branch --list --format='%(refname:short)\n%(authorname)\n%(committerdate:relative)'"
	corfzf = "!git branch --list --remote --color=always --sort='-committerdate' --format='%(refname:lstrip=3)' | fzf --ansi --height=35% --min-height=10 --preview-window=down:3 --preview='git pretty-branch {}'"

        cor = "!git checkout $(git corfzf | cut -d' ' -f1)"


[push]
	default = current # always push to same branch name on remote

[color]
	ui = true

# faster prompt in oh-my-zsh spaceship
[oh-my-zsh]
	hide-dirty = 1
	hide-status = 0
	hide-dirty = 0

.zshrc:

# git aliases
alias such=git
alias very=git
#alias wow="git status"
alias much=git
alias got=git
alias st="git status"


if [[ "$(uname)" == "Darwin" ]]; then
    fpath=(/usr/local/share/zsh-completions $fpath)
    # regenerate with: rm -f ~/.zcompdump; compinit
    source "/usr/local/opt/zsh-git-prompt/zshrc.sh"
    source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
    source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment