How to orphan your master branch
Published on 18 Feb 2021
I recently created a small Rails app to demonstrate delegated types, but when I pushed it to Github, the first commit included all the files in tmp
and node_modules
.
I removed them from the branch and pushed follow-up commits, but the history of these files remained in my Git history.
Here is an easy solution from Stackoverflow:
# Checkout
git checkout --orphan latest_branch
# Add all the files
git add -A
# Commit the changes
git commit -am "orphaned master branch"
# Delete the branch
git branch -D master
# Rename the current branch to master
git branch -m master
# Finally, force update your repository
git push -f origin master