Skip to content

Instantly share code, notes, and snippets.

@ptdecker
Created October 31, 2024 20:05
Show Gist options
  • Save ptdecker/cbaa882d8f6ece64408fea9104e4dc45 to your computer and use it in GitHub Desktop.
Save ptdecker/cbaa882d8f6ece64408fea9104e4dc45 to your computer and use it in GitHub Desktop.
Quick recovery from accidental commit of changes to local main instead of to a branch
# Assumes local main was current with remote main prior to the fuck up
# Create a new branch containing prior local main + changes
git checkout -b {local branch name}
# Switch back to local main
git checkout -
# Delete local main (which also contains the additional changes)
git branch -D main
# Check out remote main (which matches what was local main before changes)
git checkout main
# Switch back to new branch which would contain the changes
git checkout -
@NerdyDeedsLLC
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment