Tomas Vik

Git

Delete all tags:

  • git tag | xargs git tag -d
    

Range diff:

  • # Diff the diffs using `git range-diff`
    git range-diff ${PREVIOUS_TAG}..main ${NEW_TAG}..update-fork-to-${NEW_TAG}
    

is the working directory dirty?

  • if [ -z "$(git status --porcelain)" ]; then

Counting the lines of code in a Git repository git ls-files | xargs wc -l

Starting a new orphan commit in a repository git checkout --orphan branch-name

Remove a file through the whole history (good when you commit a binary or secrets by accident)

  • git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch path_to_file' HEAD
    

HTTP credentials

  • Git sometimes caches the credentials. On MacOS, you see that git config --get credential.helper returns osxkeychain and you can find the cached credentials in keychain under the domain name (e.g. gitlab.com)