Created
October 31, 2024 20:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/NerdyDeedsLLC/738ef4ca48d91db55a811a8054a00430