Skip to content

Instantly share code, notes, and snippets.

@daaimah123
Created June 5, 2021 02:37
Show Gist options
  • Save daaimah123/bbb27daf47e7a3c79199a2ef50abcb98 to your computer and use it in GitHub Desktop.
Save daaimah123/bbb27daf47e7a3c79199a2ef50abcb98 to your computer and use it in GitHub Desktop.

Find all merged branches

git branch --merged | grep -v \* | xargs

Delete all merged branches

git branch --merged | grep -v \* | xargs git branch -D

Delete all excluding main

git branch | grep -v "main" | xargs git branch -D

Retrieves failed commit messages

git commit -e --file=$(git rev-parse --git-dir)/COMMIT_EDITMSG

Git stash

Try git stash apply instead of git stash pop to avoid losing saved changes

git stash save <message>
git stash apply stash@{#}

Remove file / directory from entire tree history

You know when you accidentally commit "." files this will take a while but it will walk through every committed instance of the file and directory on your branch and remove it, your will have to force the push to see results on remote. USE WITH EXTREME CAUTION

git filter-branch --tree-filter 'rm -rf <file-or-directory-to-be-removed> HEAD

Quick version, does not check the tree

git filter-branch --index-filter 'rm -rf <file-or-directory-to-be-removed> HEAD

Rewrite a commit

Rebase, then replace pick with reword, save/exit, the commit window will open for editing, save and force push

git rebase -i <commit_hash>^
reword <commit_hash>
:wq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment