Rename the current branch
git branch -m <newname>
# Find when a string was modified $ git log -S "find_me" --source --all -p # Show the entirety of the changes
Easily switch between branches by "stashing" current changes instead of committing them.
git stash list # Available stashes git stash [-u] # Stash current changes (-u stashes new files too) git stash pop (stash{1}) # Restore a (specific or latest) stash git stash drop stash{0} # Delete a stash git stash show -p # Peak at a stash
// Gather 2 commits into one $ git rebase -i HEAD~2 // Undo the previous commit $ git reset HEAD~
Delete branches
$ git push origin --delete branch_name $ git branch -d branch_name br=branch_name; git branch -D $br; git push origin :$br # .gitconfig [alias] nuke = "!f(){ git branch -D \"$1\"; git push origin --delete \"$1\"; };f" $ git nuke branch_name
Find which branch a commit SHA1 originates from
git log <COMMIT SHA>..HEAD --ancestry-path --merges (--oneline)
"cherry pick" a file from another branch
# To run from the branch you want to bring the file to $ git checkout branch_where_the_file_is path/to/the/file
[Recover a dropped stash](https://stackoverflow.com/questions/89332/how-to-recover-a-dropped-stash-in-git)
$ git stash pop [...] Dropped refs/stash@{0} (2ca03e22256be97f9e40f08e6d6773c7d41dbfd1) # (Note that git stash drop also produces the same line.) # To get that stash back, just run git branch tmp 2cae03e, and you'll get it as a branch. To convert this to a stash, run: $ git stash apply tmp $ git stash