🖖 Greetings, this site is prototype for low code CMS deployments: Discover MoreStar on GitHub

SKNOW.IT

Cover Image for How to completely clear git repository, without deleting it

How to completely clear git repository, without deleting it

Local git repository only

To erase your whole history and start over again, run the commands below and start committing again:

cd <repo>
rm -rf .git
git init

If you want to remove both files and history, run the commands below and start committing again:

cd <repo>
rm -rf *
git init

Local repo with a remote repository

To start over again, but retain history there is a quick way:

git pull
git rm -r *
git commit
git push

To also clean up the history (N.B. this will cause trouble for anyone else linked to that same remote repository):

git checkout <first commit hash>
git rm -r *
touch README
git add README
git commit --amend
git push -f

Create an empty README file for the first commit, as a commit cannot be empty.

Refs:

GET IN TOUCH

Site Mod
Site Mod
Wrote this on
Categrised as:
DevelopmentSnippets

Tagged#HowTogitversion-control


More Articles

Cover Image for How to Check and Update Your Git Version

How to Check and Update Your Git Version

Change is inevitable and, in the technical world, usually beneficial. Keeping your Git installation up to date is highly recommended, it gives you all the latest features, improvements, bug fixes, and more. Let’s see how to check which Git version you’re currently using and how to update it to the latest version. To stay up […]

Read More… from How to Check and Update Your Git Version

Shaun Knowles
Shaun Knowles
Cover Image for Next Generation Eco Friendly WordPress Websites

Next Generation Eco Friendly WordPress Websites

Do you want a WordPress website that is truly unique and reflects your brand? We design and build high performance websites for all purposes. […]

Read More… from Next Generation Eco Friendly WordPress Websites

Shaun Knowles
Shaun Knowles