You can get away with this with branches or folders, but it's a prime candidate IMO for submodules. I use them for such things. Here's an example set of 3 repos:
common/ (bare repo of common files)
.git/
wp7/ (regular repo of wp7 specifics)
.git/
common/ (submodule)
wp8/ (same as wp7, but for wp8)
.git/
common/ (submodule)
To make the common one you would just take a regular repo and git clone --bare repo optional_bare_repo_name
. If you don't give it a name, it'll clone common
into a folder called common.git
, which is the bare version. Now you can from within either wp repo do git subdmodule add path/to/common optional_folder_name
(it uses the repo folder name if you don't specify one). This effectively clones the common repo into a folder inside each wp repo. These can also be branches of a single repo; you'd just do the submodule add while on each branch.
Submodules are slightly more maintenance than branches, but they do something branches can't. They give you a parallel line of development inside your repo. When you make a change in the common repo inside either wp repo, you commit it there, and you can push it back to the external, bare version of common, and pull it down in the other wp repo's common repo. It's just a regular repo, but its clones live inside the wp repos. In your wp repos you would tell it which version you want right now by first checking out the correct commit inside the common repo, then outside in the wp repo doing git add common
and git commit -m'Update common for feature X'
. This creates a commit in the wp repo that just stores the hash of the commit in the common submodule.
When you checkout this commit in the wp repo later, it'll checkout the wp code, and also the appropriate commit in the common repo. Basically you're able to track which version of the common repo to be at at particular times. This is nice for a couple of reasons. For one, you don't have to get latest in common in a particular wp repo if you don't want or need it. It also means you can actually checkout an older commit in either common repo, add it, and commit it in that wp repo, and then work against that older one for as long as you need to. It is a little more work, though, and you have to remember to work in the wp and common repos together. I do it every day, but I've heard many people say it's too much bother.
You can also add and commit a particular version of common along with files in a wp repo, so for example you could go in and refactor things in common, hop out and fix changes against that refactoring in wp7, then add common and the wp7 changes together in wp7 and commit them to track both changes. Now if you roll back 1 commit the common repo will also roll back to before the refactoring, so you can have properly functioning code at every commit.