Git Subtree & Git Submodules With WordPress

While undergoing one of my goals, “to automate as many technicalities as possible”, I decided to revisit Git Submodules. Really, I would of been better off visiting the Inuit’s village with the hopes turning them all vegan.

Submodules

The concept behind submodules seems great. There’s plenty of reading elsewhere for details, but in short “it’s a repository inside a repository”. Simple enough so I thought. I spun up a repository and everything was going smooth, until I decided to clone my repository that included submodules.

Now I had what’s known as a super-project, a cloned repository of other sub-modules. It became confusing fast, documentation is cryptic and most of it seems discouraging. While I was at ZendCon in summer of 2011 I asked a few GitHub guys about it, and the consensus was that it’s really not recommended. Still I decided to explore more.

Subtree Merge Strategy

An alternate approach was the subtree merge strategy, here’s the “how to” care of, Scott Chacon (GitHub’s CIO).

$ git remote add -f Bproject /path/to/B
$ git merge -s ours --no-commit Bproject/master
$ git read-tree --prefix=dir-B/ -u Bproject/master
$ git commit -m "Merge B project as our subdirectory"
$ git pull -s subtree Bproject master
Yeah, right, that does not look fun. Managing your code should be a simple and thoughtless act. If you’re spending more time figuring out how to get changes in and out of the repository (all for the sake of history, cause you want to blame developers right?) you have bigger issues to worry about.

Conclusion, Rethink What You’re Attempting Do

Your attempting to build Library A inside of Project A…thats downright selfish. That’s basically saying, “I have no coding control, and want to code on Project A, but diverge and code on Library A, while I’m supposed to be working on Project A”.

In a perfect world wouldn’t every framework be composed of submodules? WordPress, for example, would contain submodules for each of its 3rd party scripts.

Subtree merge strategy and submodules might work well with computer scientist and large scale software projects, but are overboard for most web projects.

My Alternate Work Flow For Git Subtree Merge and Git Submodule

  1. Work on Library A, add and commit, etc.
  2. Work on Project A, include Library A (ONLY when its complete).
  3. Found a bug or want to add a new feature in Library A?
  4. Stop, look up the word DISCIPLINE in a dictionary (I can avoid this step since I’ve learned the meaning of the word discipline).
  5. Add to your features or bugs list (every “good developer” uses a features and bugs list right? no most of them just get into “code masturbation”).
  6. At a later time revisit the list of features and/or bugs for Library A.
Remember…

“Add little to little and you will be left with a big pile” – The Mythical Man Month

Leave a Reply