Get updates via: rss | twitter | email

Clean a git repo

Written by
Date: 2020-04-26 19:05:00 00:00

Today I needed to start a new blog, in order to post about another topics not related to Linux, FOSS, server admin and so on.

I did not want to start from zero, yes I am lazzy, so I just copy the git repo this blog is in to another folder, and from there I had to remove all posts, images and site specific files, and keep css, js and template files (This and the other site are static sites, generated using Middleman).

So, let's go to the process:

Copy the comple folder, in my case it was:

cp -r old-blog new-blog

Then go inside new-blog folder and switch origin.

git remote set-url origin https://github.com/USERNAME/new-blog.git

Be sure the change is done.

git remote -v

You should get something like this:

origin  https://github.com/USERNAME/new-blog.git (fetch)
origin  https://github.com/USERNAME/new-blog.git (push)

This step is very important as the old-blog repository is not supposed to be deleted, nor modified.

Now create a new branch an orphan one:

git checkout --orphan newBranch

Now commit all changes

git commit -am 'new repo'

Now it is time to delete the master branch

git branch -D master

And make the new branch the master one.

gir branch -m master

Let's now push changes to the server.

git push origin master

Your are all done.