2

Here is the workflow I am aiming for:

Git Workflow

I have two repositories. One for the website framework coded in PHP, and the other is for custom PHP code for added website features the client wants.

I need to be able to pull from both repositories for the client website but only push to one, which would be the custom code, and I only want that second repository to hold the custom code, not the framework.

How can I achieve this?

I have both repositories added but it always does a merge (because I use git pull) but if I use just git remote update my files are not changed.

Steps I took for the setup:

Remote:

mkdir ~/git/framework.git
cd ~/git/framework.git
git init --bare

mkdir ~/git/client1.git
cd ~/git/client1.git
git init --bare

Local:

mkdir ~/www/framework
cd ~/www/framework
git init
git remote add framework ssh://user@host/~/git/framework.git

mkdir ~/www/client1
cd ~/www/client1
git init
git remote add framework ssh://user@host/~/git/framework.git
git remote add client ssh://user@host/~/git/client1.git

Here is my local client config:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "framework"]
    url = ssh://user@host/~/git/framework.git
    fetch = +refs/heads/*:refs/remotes/framework/*
[remote "client"]
    url = ssh://user@host/~/git/client1.git
    fetch = +refs/heads/*:refs/remotes/client/*
Draven
  • 1,467
  • 2
  • 19
  • 47
  • @true I looked and didn't see anything in there that would help me... – Draven Aug 09 '14 at 00:01
  • So in these types of problems, there isn't a out-of-the-box-solution that is going to work. You will have to invent it yourself. Bash scripts and git hooks will probably help. (My intention isn't to sound mean) – Ryan Aug 09 '14 at 00:04
  • Git is very fun. Especially since you have multiple machines. My advice would be to get a 12 pack of red-bull sit down one night, and design a build system for your application. – Ryan Aug 09 '14 at 00:18
  • @PaulHicks any blog posts that can provide more detail into that design? – Ryan Aug 09 '14 at 00:20

1 Answers1

2

For your pattern, you can declare one of the repositories read-only, as per this answer (several suggestions). Then you can use git pull client and git pull framework to sync up, and git push client to push your code. To set client as your default remote, you can do git branch --set-upstream-to client/master (or replace master with whatever remote branch you want to push to by default).

A more common pattern is to use branches to keep framework and client separate. This also means you need only two repositories: your shared bare repository, and your local development one. You can pull from origin, which has main two branches, framework and client. You can choose what to merge from framework into client, and you'd (almost) never merge from client back to framework.

Community
  • 1
  • 1
Paul Hicks
  • 13,289
  • 5
  • 51
  • 78
  • If I understand correctly, when using the branches the way you explained, would mean that the client branch would have the framework AND custom code in it, right? I'll have to talk to my second developer about if we should do that. – Draven Aug 09 '14 at 14:55
  • Another thing I just thought of is we'll have multiple clients so there'd have to be a `framework`, `client1`, `client2`, `client3`, and so on branches. That won't work for us. – Draven Aug 09 '14 at 17:07
  • Git is really good at having lots of branches. But whatever works for you. For me, a single deployment effort comes from a single repository, whether that means a single library or 4 applications. But git is flexible and will work whatever way you want it to. – Paul Hicks Aug 09 '14 at 18:15
  • Appreciate you sharing your knowledge of Git with me, in terms I can understand. I've only been using Git a few days and I am really liking it. A lot easier to use then Subversion. Only thing I have a problem with is Git takes 2 commands to update the repository (`git commit` then `git push`), compared to just `svn commit` – Draven Aug 09 '14 at 18:45
  • I thought this worked but it turns out it does add the `client1` data into the `framework` repository. – Draven Aug 11 '14 at 18:38
  • That's because you've set up `framework` as your default remote repository. Either use `git push client1`, or turn off pushing of `framework` (not sure how to do this using git command, I just edit the `.config` file in the local reposiory, it's self explanatory). – Paul Hicks Aug 11 '14 at 22:00
  • I noticed I made `frameword` default and changed that. The problem I am having is that I get `framework` data in the `client` repo, which makes sense since I am adding the `framework` as a remote. As close as I can get is using rebase which seems like it just tracks the files but doesn't add them into the repo. I'd like the `framework` and `client` reoo's to run parallel in the same folder without adding any data from one into the other. – Draven Aug 11 '14 at 22:06
  • What would happen if a file appeared in both repositories? You'd pull one from `framework`, pull it from `client`, merge it, then somehow unmerge-on-push to `client`? I don't think there's an easy way to say this: the model you're trying for is seriously and fundamentally flawed and should not be pursued. Some seriously smart people have been working with source control for several decades, yet I've never read anything about how to support what you're trying to do. My advice is to change your model now, before it starts to cripple your output. – Paul Hicks Aug 11 '14 at 22:20
  • 1
    I'm with you Paul. lol. Unfortunately, this model is what was given to me. I am going to try to talk him into doing it the way I have it setup currently which is just rebasing the `framework` into the `client`. Seems to work nicely. – Draven Aug 11 '14 at 22:50