tags:

views:

93

answers:

2
+2  Q: 

Git and cloning

Hi all!

I have done an app for a client called 'A' (not really).

I have found out that it is very cool and that I want to sell it to other clients also. The directory 'A' is a Git repository. I think I have a problem with cloning it. As far as I can see I need to make a copy of the dir 'A' and call it 'Generic_A'. Then delete the dir 'A' and do a "git clone Generic_A A" Then I could start changing the 'Generic_A'-repo with a generic design and all client references removed. But that is kind of the other way around. I should have started doing the generic design and then cloned the repo to change to the client specific design.

Can I:

  1. make a new branch
  2. do all the changes to make the design generic
  3. create a patch that reflects the changes between the two
  4. remove the client specific branch
  5. rename the directory to 'Generic_A'
  6. clone the repo to a new dir 'A'
  7. apply the patch to get the client specific stuff back

And if yes - how do I make the patch and apply it?

Regards,

Jacob

A: 

That could work, although between 6. and 7. I would make a 'client_A' branch before applying your patch.
The drawback is that you lose commit history specifics to client A, since you apply that patch in one big commit.

In your case, a patch can be made with git diff, see patching with git diff

git diff --no-prefix > patchfile

then apply the patch:

patch -p0 < patchfile

If you have an existing "git diff" patch file that was created without the "--no-prefix" option, you can apply that patch via:

patch -p1 < patchfile

this will ignore the default a/ b/ source prefixes.

VonC
Thanks a lot for your reply. Why would you make the 'client_A' branch? Why not just apply the patch on the master branch? It is after all a clone of the generic one.
jriff
BTW - I know about loosing the history but I can live with that in this case.
jriff
@jriff: a ``client_A` branch allows you to leave the master branch alone, ready to be updated by your `Generic_A` master evolutions when you make the next `git pull`
VonC
+1  A: 

Here a possible work-flow :

  • On A dir :
    • Create a new branch 'generic' from branch 'client-A'.
    • Use 'git rebase -i' on 'Generic' branch to remove all client A stuffs.
    • Use 'git rebase client-A generic' to rebase your client-A branch on the generic one.
  • Rename your A dir to generic dir
  • clone your generic dir to a new client-A dir
  • remove client-A branch from generic dir.

This way, you will keep the history of the client-A branch.

Matthieu Gautier