Accidentally commited to a deleted branch. How can a create a new branch with the changes?

I accidentally committed to a branch that is deleted. I tried pushing and it gave me an error.

How can I create a new branch with the changes I already made?

hi @Jonathan-Hernandez :grinning:! try the following steps:

  1. Check out the branch that had the changes you want to keep:
git checkout <name-of-deleted-branch>
  1. Create a new branch to hold the changes:
git checkout -b <new-branch-name>
  1. Cherry-pick the commit(s) you want to keep from the deleted branch:
git cherry-pick <commit-hash>

If you have multiple commits that you want to apply to the new branch, you can list them all separated by a space

  1. Once you’ve cherry-picked all the desired commits, push the new branch to the remote repository:
git push -u origin <new-branch-name>

This will create a new branch with the changes you’ve made