Skip to main content

Rewriting History

I often flesh out ideas with actual code. Most of the time this is simply a sketch exercise. Sometimes though, I work on this "sketch" enough that it becomes the "work". This is usually not an issue. However, like a sketch, I throw together ideas; jotting them down if you will. 

The current project I am working on started this way. It is now at the point where I have deliverables and glaring issues from my choices. Issues to me at least. For instance, all pieces are in one git repository. This is not a huge deal. Personally, I prefer the import, mobile, and web folders to be their own repository to keep their commits and tags cleaner.

Splitting a Repository

A quick search provided two ways to move a subfolder to a new repository. This help guide from github uses filter-branch, which comes with a warning:

git-filter-branch is riddled with gotchas resulting in various ways to easily corrupt repos or end up with a mess worse than what you started with

This did not work as well as The Easy Way described in a StackOverflow answer. Here is the run down of The Easy Way using my example repository Project-A

Change the Committing Account

Suppose I started hacking away at my keyboard, never realizing I was committing changes with the wrong git account. This sounds crazy I know. 

This article from Github provides the directions to correct the email and username using filter-branch for past commit history. Despite the dire warning, it worked! In short:

  • change the OLD_EMAIL, CORRECT_NAME, and CORRECT_EMAIL in the script below
  • paste corrected version into git bash
  • press [ENTER]
  • push to new repository on Bitbucket or Github or ??