nisanth
Wed Sep 27 2023
When we create a branch and make numerous commits to it, and later decide to start fresh by removing those previous commits, we can do this by following these steps in the terminal:
- Delete the branch locally:
git branch -D <branch name>
- Recreate the same branch from the ‘main’ branch:
git checkout main
git checkout -b <branch name>
- Commit and push your changes:
git commit -m "Your commit message"
git push origin <branch name> -f
By using the-f
flag in the ‘git push’ command, you force-push the changes to the branch on the remote repository. This erases the previous commits from the branch, giving you a fresh start with your new commit.”