author avatar

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:

  1. Delete the branch locally: git branch -D <branch name>
  2. Recreate the same branch from the ‘main’ branch: git checkout main git checkout -b <branch name>
  3. 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.”