Skip to content

DrCookies84/git-unfuck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

🔧 git-unfuck

One-liners for every git disaster you'll inevitably cause.

Because git is powerful, and you are reckless.


🔥 "I committed to the wrong branch"

# Undo the last commit but keep your changes
git reset HEAD~1

# Move it to the correct branch
git stash
git checkout correct-branch
git stash pop
git add .
git commit -m "your message"

🔥 "I pushed a secret / API key"

# Remove the file from git history (nuclear option)
git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch path/to/secret-file" \
  --prune-empty --tag-name-filter cat -- --all

# Force push (yes, you have to)
git push origin --force --all

# Then rotate your key immediately. The old one is compromised.
# Git history is cached by GitHub — even after force push,
# the old commits are accessible for ~90 days via SHA.

🔥 "I committed to main instead of a feature branch"

# Create the branch you meant to commit to (keeps your commits)
git branch feature-branch

# Reset main back to before your commits
git reset --hard origin/main

# Switch to your feature branch — your commits are there
git checkout feature-branch

🔥 "I need to undo the last commit completely"

# Undo last commit, keep changes staged
git reset --soft HEAD~1

# Undo last commit, keep changes unstaged
git reset HEAD~1

# Undo last commit, destroy changes forever
git reset --hard HEAD~1

🔥 "I already pushed and need to undo it"

# Revert creates a NEW commit that undoes the old one (safe for shared branches)
git revert HEAD
git push

# Nuclear option — rewrites history (only if nobody else has pulled)
git reset --hard HEAD~1
git push --force

🔥 "I accidentally deleted a branch"

# Find the last commit on the deleted branch
git reflog

# Look for the commit hash, then recreate the branch
git checkout -b recovered-branch abc1234

🔥 "I made a typo in my last commit message"

# Amend the most recent commit message
git commit --amend -m "fixed message"

# If already pushed
git push --force

🔥 "I need to unstage a file"

# Unstage a specific file (keeps changes)
git reset HEAD filename

# Unstage everything (keeps changes)
git reset HEAD

🔥 "My merge is fucked and I want to start over"

# Abort the merge and go back to before you started
git merge --abort

# If you already committed the merge and it's wrong
git reset --hard ORIG_HEAD

🔥 "I need to see what changed in a specific commit"

git show abc1234

🔥 "I need to find which commit broke something"

# Binary search through commits
git bisect start
git bisect bad              # current commit is broken
git bisect good abc1234     # this old commit was working
# Git will checkout commits for you to test
# Mark each as good or bad until it finds the culprit
git bisect reset            # when done

🔥 "I want to completely nuke my local repo and start fresh"

# Delete everything and re-clone
cd ..
rm -rf your-repo
git clone https://github.com/you/your-repo.git

🔥 "I committed a huge file and now I can't push"

# Remove the large file from the last commit
git rm --cached huge-file.zip
git commit --amend -m "remove large file"

# If it's in older commits, use BFG Repo-Cleaner
# https://rtyley.github.io/bfg-repo-cleaner/
java -jar bfg.jar --strip-blobs-bigger-than 100M
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force

🔥 "I need to cherry-pick a commit from another branch"

git cherry-pick abc1234

🔥 "I stashed something and can't find it"

# List all stashes
git stash list

# Show what's in a specific stash
git stash show -p stash@{0}

# Apply a specific stash
git stash apply stash@{0}

# Apply and delete the stash
git stash pop stash@{0}

🔥 "Git says 'detached HEAD' and I'm scared"

# You're not on a branch. Create one from where you are
git checkout -b new-branch-name

# Or go back to an existing branch (your uncommitted work may be lost)
git checkout main

🔥 "I want to undo ALL local changes and match remote"

git fetch origin
git reset --hard origin/main
git clean -fd

🔥 ".gitignore isn't ignoring my file"

# Git already tracks the file. Remove it from tracking (keeps local copy)
git rm --cached filename
git commit -m "stop tracking filename"

# For a whole directory
git rm -r --cached directory/
git commit -m "stop tracking directory"

💡 Pro Tips

  • Before doing anything destructive: git reflog is your black box recorder. It logs every HEAD movement for 90 days.
  • When in doubt: git stash your changes first. You can always git stash pop to get them back.
  • Never force push to shared branches unless you've warned everyone on the team.
  • Rotate your secrets immediately after removing them from git history. The exposure already happened.

License

MIT — Because even your mistakes should be open source.


Built by DrCookies84 — who has made every single one of these mistakes at least twice.

About

One-liners for every git disaster you will inevitably cause. Because git is powerful, and you are reckless.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors