Skip to content
alex [dot] kramer [at] g_m_a_i_l [dot] com edited this page Aug 30, 2023 · 31 revisions

Configuration

⏣SUPERIOR ULTRABEST™⏣ Git config. Provides fancy-pants aliases, sane default settings, and other useful miscellanea:
https://github.com/mitochondrion/dotfiles/blob/master/.gitconfig
https://github.com/mitochondrion/dotfiles/blob/master/.gitignore

Set up git hooks

Allow git hooks to be checked in with the repo

git config core.hooksPath .githooks

Debug git command

GIT_TRACE=2 [GIT_COMMAND]

Grep across all branches/commits

git log -G[REGEX] --branches --all

Find commits that add/remove specific text in a file

git log -c -S'missingtext' /path/to/file

Bisect

git bisect start
git bisect good [working commit]
git bisect bad [broken commit]
git bisect [good|bad] # repeat until git finds the first bad commit
git bisect reset

Rebase fork onto upstream

git remote add upstream git://github.com/[UPSTREAM_REPO].git
git fetch upstream -p
git rebase upstream [BRANCH]

Resolve one-sided merge conflict

git checkout --ours [FILE]
git checkout --theirs [FILE]

Show all stashes

git stash list | awk -F: '{ print "\n\n\n=========="; print $0; print "==========\n\n"; system("git stash show -p " $1); }'

Cleanup

Clean local branches

git branch
git co develop
git branch --merged
git branch -d [MERGED BRANCH TO DELETE]
git branch --no-merged
git branch -D [UN-MERGED BRANCH TO DELETE]

Clean remote branches

git fetch -p (OR git remote prune origin)
git branch -r
git branch -r --merged
git push origin --delete [REMOTE BRANCH TO DELETE]

List remote merged branches

Merged:

for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r

Un-merged:

for branch in `git branch -r --no-merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r

Remove a pushed /Pods folder

git filter-branch --index-filter 'git rm --cached --ignore-unmatch Pods/*' --tag-name-filter cat -- --all
git push --force

Tags

Move tag:

git fetch -p --tags
git tag -d [tag]
git tag [tag]
git push --tags -f

Latest tag:

git describe --abbrev=0 --tags

Tag of current commit:

git tag -l --points-at HEAD

Show all commits for a file

git log --follow BRANCH -- FILE
Clone this wiki locally