Skip to content

Instantly share code, notes, and snippets.

@serial
Created July 29, 2021 10:36
Show Gist options
  • Save serial/71d7712ff48a41ffe7dfbe28178a4e90 to your computer and use it in GitHub Desktop.
Save serial/71d7712ff48a41ffe7dfbe28178a4e90 to your computer and use it in GitHub Desktop.
GitHub - Delete commits history

Deleting the .git folder may cause problems.
If we want to delete all of our commits history, but keep the code in its current state:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

# Commit the changes:
git commit -am "Initial commit"

# Delete the old branch:
git branch -D master

# Rename the temporary branch to master:
git branch -m master

# Finally, force update to our repository:
git push -f origin master

NOTE: You need to provide your GitHub account credentials.

Reset tracked files [git docs](https://git-scm.com/docs)

# Update or remove previously tracked files from the entire working tree (it will not add new files).
git add -u

# Reset current HEAD to the specified state
git reset -- <file | folder>

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