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
all tags
activerecord android annoyances api apt arch array artix atom az3w backend bash blog browser bug callback career cli cloud code coding config configuration cp crud css database db design devops django email erp filter fugitive gif gist git gnome grep hebrew http ide isbn-fetcher iso javascript job search js kanban kanban\ kindle koans linux logger manjaro map markdown microservices mobi mtp neovim nodejs packages pastbin patch post python rails reduce refactoring rest routes rspec ruby scripting security sed shell sql string_replacement study tdd terminal testing version_control vim walkthrough workflow