tags:

views:

66

answers:

3

Hi community,

I have a product which comes in two versions, and up to now I was able to manage the differences between them only using compiler flags and #ifdefs. Now I want to have a separate icon for each of the product. The rest of the codebase, including source referencing the icon file remains the same. I want to keep these development streams in git branches (say, master, pro, and lite), but want branches pro and lite to (a) only contain different icon.png files, and (b) automatically contain all changes made to any files in branch master.

In Subversion this could be done by branching a single file (icon.png). Is there a way to do something similar in git?

+1  A: 

Just create a branch: git checkout -b branchName and replace the icon. And git commit, of course. After that you can work in the parent branch (or in master if you prefer) and use git rebase to pull the changes into branchName

Dmitry
Combination of local tracking branch and git rebase was the only thing that worked exactly like I needed, thanks!
Sergey Mikhanov
A: 

Just branch and commit the icon. Should be just fine in Git like that. Then you'd just merge when you want to include the changes from other branches.

Jani Hartikainen
+1  A: 

You cannot create a branch for a single file in Git. When you create a branch, you create a branch for the entire repo. (Of course, unlike Subversion, a branch does not create actual on-disk copies of your files, so branches are cheap and don't take up as much extra space as a Subversion branch.)

It sounds like the branch for this icon change is going to be a long-running branch, i.e., it'll have changes merged from master, but it's changes won't be merged back to master often, and you'll pretty much keep the branch around permanent. In that case, you should set up the branch to automatically track the master branch. You can set this up by passing the --track option to git branch or git checkout, when creating the new branch (see the man page for git branch for more details).

mipadi
Thanks for the hint! Branches pro and lite are indeed long-lived, and because of that I created them as remote (git push origin master:refs/heads/pro) and I have local copies tracking each of them. Is there a way to force remote pro and lite to track remote master?
Sergey Mikhanov
No, but your local branch can track master as noted in my answer, and those changes will get pushed out when you push to your remote.
mipadi