Monday, April 30, 2012

Git, multiple projects with similar features or roots

Todays post is about how I found a blog post that describes how to use git to branch to a new project and then run both projects simultaneously while still being able to pull new features from one to the other.

The essence of all of this is held in this awesome post: http://programblings.com/2008/07/21/setting-up-a-long-term-fork-with-git/

Really I just use that straight up.  The only thing that confused me a bit is how to use it properly.  I was finding that it was hard to maintain the link between the two depots without accidentally bringing changes across that were not meant to be.

For instance, my database connection strings.  After the fork I changed them to point to my new (but similar) projects new DB.  Then I developed a couple of fixes so I pushed them to my "connecting" depot, merged and pushed to my old depot.  I have just now over-written my db connection strings.  Whoops.

My answer? To make any changes that might be a feature I want to bring across in a branch.  It is far easier to cherry pick changes from a branch than to figure out all the different CL's I need to bring across. That and I'm no git expert and I still need to read a good book about it so there are several things that are lost on me or seem far more complex than they really are, for example commits, the hash tag, how to nicely view a list of them, how to use them properly.  Every example I've seen uses bash scripting voodoo (ok, it's not that complex) to get the hash tag to flow from one git command to the next, in perforce it was just an easy to read and distinguish number I could copy and paste and understand as a human, I liked that.

Rant over.

So, for my own reference, the exercise for the user was possibly to create your own working copy.

mkdir working_copy
cd working_copy
git init
git remote add origin /path/to/repo
git pull origin master

That does that, depending on which repo you want, add that path as the origin.

Next, cherry picking without having to work out all the hashes.

git gui

That's pretty much the answer.  I will explain how I personally do it in the next post.

1 comment: