Skip to content

Instantly share code, notes, and snippets.

@rflpazini
Last active June 15, 2019 05:05
Show Gist options
  • Save rflpazini/d53ae211a0bf04b8a7c717152e086ba2 to your computer and use it in GitHub Desktop.
Save rflpazini/d53ae211a0bf04b8a7c717152e086ba2 to your computer and use it in GitHub Desktop.
Remove all commits from a git branch

Glorious Method

# Clone the project, e.g. `myproject`:
git clone <project-url>

# Since all of the commits history are in the `.git` folder, we have to remove it:
cd myproject

# And delete the `.git` folder:
git rm -rf .git

# Now, re-initialize the repository:
git init
git remote add origin <github-url>
git remote -v

# Add all the files and commit the changes:
git add --all
git commit -am "Initial commit"

# Force push update to the master branch of our project repository:
git push -f --set-upstream origin master

Have fun 🤓

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