{"thread":{"id":"27864","subject":"can I use multiple worktree in same git repo ?","startedAt":"2011-07-20T12:54:38Z","lastAt":"2011-07-22T09:06:44Z","messageCount":9,"participants":["J. Bakshi","Nguyen Thai Ngoc Duy","Jakub Narebski","Fredrik Gustafsson","Sergio"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"171733","messageId":"20110720182438.3c40cf1d@shiva.selfip.org","threadId":"27864","inReplyTo":null,"subject":"can I use multiple worktree in same git repo ?","fromName":"J. Bakshi","fromEmail":"joydeep@infoservices.in","sentAt":"2011-07-20T12:54:38Z","receivedAt":"2011-07-20T12:54:38Z","isPatch":false,"sender":{"key":"joydeep@infoservices.in","avatar":null},"body":"Hello list,\n\nPlease bear with me as I am from svn domain and gradually making myself aware of git.\n\nI have a site under htdocs which is modified by svn with the help of post-commit hook. But the svn folder structure is little different than the actual structure at filesystem.\nUnder htdocs/demo, say I have dir1, dir2 etc... where in svn I have the structure as \n\n[svn]\nmysite-repo\n|\n|----------dir1------|trunk----src (here actually I have the contents of dir1)\n|----------|---------|tags\n|----------|---------|branches\n|\n|----------dir2------|trunk----src (here actually I have the contents of dir2)\n|----------|---------|tags\n|----------|---------|branches\n\nAnd in file-system dir1 is mapped with (checkout from) and then (svn switch --relocate)  mysite-repo/dir1/trunk/src ;\ndir2 is checkout from and then (svn switch --relocate) mysite-repo/dir2/trunk/src\nand so on .....\n\nNow the post-commit hook is tricky.\n\n```````\n#!/bin/bash\n\nset -e\n\n# LANG=en_US.UTF-8 for special character support\n\nLANG=en_US.UTF-8 /usr/bin/svn up  /var/www/demo/dir1\n\nLANG=en_US.UTF-8 /usr/bin/svn up  /var/www/demo/dir2\n\nLANG=en_US.UTF-8 /usr/bin/svn up  /var/www/demo/dir3\n````````````````\n\nAs a result whenever there is a commit , it updates the related folder in filesystem.\nSay a commit at svn->mysite-repo->dir1->trunk->src ==> modify ==> /var/www/demo/dir1\n\nCan I do the same in git with multiple worktree ? possible ?\n\nThanks\n"},{"id":"171735","messageId":"CACsJy8CLRjLag65H6KQ1AUABLwiL09wNQw3VH8Y-JQnw7CqLUw@mail.gmail.com","threadId":"27864","inReplyTo":"20110720182438.3c40cf1d@shiva.selfip.org","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-07-20T13:25:55Z","receivedAt":"2011-07-20T13:25:55Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Jul 20, 2011 at 7:54 PM, J. Bakshi <joydeep@infoservices.in> wrote:\n> As a result whenever there is a commit , it updates the related folder in filesystem.\n> Say a commit at svn->mysite-repo->dir1->trunk->src ==> modify ==> /var/www/demo/dir1\n>\n> Can I do the same in git with multiple worktree ? possible ?\n\nUsing multiple worktree with the same repo won't work in git because\nthe repo also have worktree-related information. But you can create a\ncentral, bare repository, then make several clones from that. Each one\nis checked out with different branches. You work on a clone and push\nto the central repo. The post-commit hook in the central repo will do\npull from it, for example\n\nfor site in dir1 dir2 dir3; do\n    cd /var/www/$site && /usr/bin/git pull\ndone\n\nAlso have a look at git-new-workdir in contrib directory of git\nrepository. I don't use it but you might find it useful.\n-- \nDuy\n"},{"id":"171740","messageId":"201107201611.p6KGBvna012304@dcnode-02.unlimitedmail.net","threadId":"27864","inReplyTo":"CACsJy8CLRjLag65H6KQ1AUABLwiL09wNQw3VH8Y-JQnw7CqLUw@mail.gmail.com","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"J. Bakshi","fromEmail":"j.bakshi@unlimitedmail.org","sentAt":"2011-07-20T16:12:09Z","receivedAt":"2011-07-20T16:12:09Z","isPatch":false,"sender":{"key":"j.bakshi@unlimitedmail.org","avatar":null},"body":"On Wed, 20 Jul 2011 20:25:55 +0700\nNguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n\n> On Wed, Jul 20, 2011 at 7:54 PM, J. Bakshi <joydeep@infoservices.in> wrote:\n> > As a result whenever there is a commit , it updates the related folder in filesystem.\n> > Say a commit at svn->mysite-repo->dir1->trunk->src ==> modify ==> /var/www/demo/dir1\n> >\n> > Can I do the same in git with multiple worktree ? possible ?\n> \n> Using multiple worktree with the same repo won't work in git because\n> the repo also have worktree-related information. But you can create a\n> central, bare repository, then make several clones from that. Each one\n> is checked out with different branches. You work on a clone and push\n> to the central repo. The post-commit hook in the central repo will do\n> pull from it, for example\n> \n> for site in dir1 dir2 dir3; do\n>     cd /var/www/$site && /usr/bin/git pull\n> done\n> \n\nThanks for your response. I am afraid that I can't understand the approach clearly but I must say that I am hopeful to see a direction.\nObviously there will be a central git repo which will have its worktree under htdocs at the same server. That's why the post-receive \nhook will update the website after each push. But the issue is mapping the structure at git which is different than the structure at \nfilesystem. And a push should reflect to its correct folder only.\n\n[git]->[mysite]->dir1/trunk/src => physically map => htdocs/demo/dir1\n[git]->[mysite]->dir2/trunk/src => physically map => htdocs/demo/dir2\n\n\nPlease tell me with little more clarification, how can I do this ?\n\n-with kind regards\n"},{"id":"171795","messageId":"CACsJy8DswCJS8YfaG=e73g1ZDVRV1H3Z0St7zaAEuuwYxgxgBQ@mail.gmail.com","threadId":"27864","inReplyTo":"201107201611.p6KGBvna012304@dcnode-02.unlimitedmail.net","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-07-21T03:20:13Z","receivedAt":"2011-07-21T03:20:13Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Jul 20, 2011 at 11:12 PM, J. Bakshi <j.bakshi@unlimitedmail.org> wrote:\n> Thanks for your response. I am afraid that I can't understand the approach clearly but I must say that I am hopeful to see a direction.\n> Obviously there will be a central git repo which will have its worktree under htdocs at the same server.\n\nNo, the central repository does not need worktree attached (in other\nwords \"bare repository\"). You modify in a clone from it and push\nto/pull from it.\n\n> That's why the post-receive\n> hook will update the website after each push. But the issue is mapping the structure at git which is different than the structure at\n> filesystem. And a push should reflect to its correct folder only.\n>\n> [git]->[mysite]->dir1/trunk/src => physically map => htdocs/demo/dir1\n> [git]->[mysite]->dir2/trunk/src => physically map => htdocs/demo/dir2\n>\n>\n> Please tell me with little more clarification, how can I do this ?\n\nOK, let's create a central repository\n\nGIT_DIR=/somewhere/safe/repo.git git init --bare\n\nThen clone it where development happens\n\ngit clone /somewhere/safe/repo.git ~/dev\ncd ~/dev\n\nNow we create \"dir1\" and \"dir2\" branches, correponding to what you\nhave in the original tree\n\ngit checkout -b dir1\n# put contents of dir1/trunk/src here, commit\ngit checkout -b dir2 master\n# put contents of dir2/trunk/src here, commit\n\nThen we push everything back to central repo\n\ngit push origin +dir1:dir1 +dir2:dir2\n\nThen we clone it to demo sites\n\ncd /var/www\ngit clone /somewhere/safe/repo.git dir1\ngit checkout dir1\n\ncd /var/www\ngit clone /somewhere/safe/repo.git dir2\ngit checkout dir2\n\nNow you can add a post commit hook to /somewhere/safe/repo.git to move\nto /var/www/dir[12] and do a \"pull\". When you push again from ~/dev,\n/var/www/dir[12] should get updated. Is that what you want?\n-- \nDuy\n"},{"id":"171797","messageId":"20110721113702.329f73b5@shiva.selfip.org","threadId":"27864","inReplyTo":"CACsJy8DswCJS8YfaG=e73g1ZDVRV1H3Z0St7zaAEuuwYxgxgBQ@mail.gmail.com","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"J. Bakshi","fromEmail":"joydeep@infoservices.in","sentAt":"2011-07-21T06:07:02Z","receivedAt":"2011-07-21T06:07:02Z","isPatch":false,"sender":{"key":"joydeep@infoservices.in","avatar":null},"body":"On Thu, 21 Jul 2011 10:20:13 +0700\nNguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n\n> On Wed, Jul 20, 2011 at 11:12 PM, J. Bakshi <j.bakshi@unlimitedmail.org> wrote:\n> > Thanks for your response. I am afraid that I can't understand the approach clearly but I must say that I am hopeful to see a direction.\n> > Obviously there will be a central git repo which will have its worktree under htdocs at the same server.\n> \n> No, the central repository does not need worktree attached (in other\n> words \"bare repository\"). You modify in a clone from it and push\n> to/pull from it.\n> \n> > That's why the post-receive\n> > hook will update the website after each push. But the issue is mapping the structure at git which is different than the structure at\n> > filesystem. And a push should reflect to its correct folder only.\n> >\n> > [git]->[mysite]->dir1/trunk/src => physically map => htdocs/demo/dir1\n> > [git]->[mysite]->dir2/trunk/src => physically map => htdocs/demo/dir2\n> >\n> >\n> > Please tell me with little more clarification, how can I do this ?\n> \n> OK, let's create a central repository\n> \n> GIT_DIR=/somewhere/safe/repo.git git init --bare\n> \n> Then clone it where development happens\n> \n> git clone /somewhere/safe/repo.git ~/dev\n> cd ~/dev\n> \n> Now we create \"dir1\" and \"dir2\" branches, correponding to what you\n> have in the original tree\n> \n> git checkout -b dir1\n> # put contents of dir1/trunk/src here, commit\n> git checkout -b dir2 master\n> # put contents of dir2/trunk/src here, commit\n> \n\nJust here, just here... The git should have dir1/trunk/src  which should update  /var/www/demo/dir1\nand  dir2/trunk/src which should update /var/www/demo/dir2\n\nThanks for your detailed clarification, very nice....\n"},{"id":"171802","messageId":"m3sjpzsdll.fsf@localhost.localdomain","threadId":"27864","inReplyTo":"CACsJy8CLRjLag65H6KQ1AUABLwiL09wNQw3VH8Y-JQnw7CqLUw@mail.gmail.com","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-07-21T18:17:57Z","receivedAt":"2011-07-21T18:17:57Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> On Wed, Jul 20, 2011 at 7:54 PM, J. Bakshi <joydeep@infoservices.in> wrote:\n> > As a result whenever there is a commit , it updates the related folder in filesystem.\n> > Say a commit at svn->mysite-repo->dir1->trunk->src ==> modify ==> /var/www/demo/dir1\n> >\n> > Can I do the same in git with multiple worktree ? possible ?\n> \n> Using multiple worktree with the same repo won't work in git because\n> the repo also have worktree-related information. [...]\n[...]\n> Also have a look at git-new-workdir in contrib directory of git\n> repository. I don't use it but you might find it useful.\n\nActually with git-new-workdir you can have multiple working\ndirectories associated with single repository, by the way of symlinks.\n\nNote however that if you intend to *work* in those workdirs, they\nbetter correspond to different branches... or you can mess something\nheavy.\n\n-- \nJakub Narebski\n"},{"id":"171804","messageId":"20110721182215.GA9505@kolya","threadId":"27864","inReplyTo":"m3sjpzsdll.fsf@localhost.localdomain","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2011-07-21T18:22:15Z","receivedAt":"2011-07-21T18:22:15Z","isPatch":false,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"On Thu, Jul 21, 2011 at 11:17:57AM -0700, Jakub Narebski wrote:\n> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n> \n> > On Wed, Jul 20, 2011 at 7:54 PM, J. Bakshi <joydeep@infoservices.in> wrote:\n> > > As a result whenever there is a commit , it updates the related folder in filesystem.\n> > > Say a commit at svn->mysite-repo->dir1->trunk->src ==> modify ==> /var/www/demo/dir1\n> > >\n> > > Can I do the same in git with multiple worktree ? possible ?\n> > \n> > Using multiple worktree with the same repo won't work in git because\n> > the repo also have worktree-related information. [...]\n> [...]\n> > Also have a look at git-new-workdir in contrib directory of git\n> > repository. I don't use it but you might find it useful.\n> \n> Actually with git-new-workdir you can have multiple working\n> directories associated with single repository, by the way of symlinks.\n> \n> Note however that if you intend to *work* in those workdirs, they\n> better correspond to different branches... or you can mess something\n> heavy.\n\nIt would be possible to use the .git-file feature here. Then symlinks are\navoided and the solution is portable.\n\nMed vänliga hälsningar\nFredrik\n"},{"id":"171810","messageId":"201107212050.20108.jnareb@gmail.com","threadId":"27864","inReplyTo":"20110721182215.GA9505@kolya","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-07-21T18:50:19Z","receivedAt":"2011-07-21T18:50:19Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Thu, 21 Jul 2011, Fredrik Gustafsson wrote:\n> On Thu, Jul 21, 2011 at 11:17:57AM -0700, Jakub Narebski wrote:\n\n> > Actually with git-new-workdir you can have multiple working\n> > directories associated with single repository, by the way of symlinks.\n> > \n> > Note however that if you intend to *work* in those workdirs, they\n> > better correspond to different branches... or you can mess something\n> > heavy.\n> \n> It would be possible to use the .git-file feature here. Then symlinks are\n> avoided and the solution is portable.\n\nActually it wouldn't.  Each new workdir has a separate HEAD and a\nseparate index; it is contents of .git that is symlinked, not .git\nitself.\n\n-- \nJakub Narebski\nPoland\n"},{"id":"171835","messageId":"loom.20110722T105732-905@post.gmane.org","threadId":"27864","inReplyTo":"201107212050.20108.jnareb@gmail.com","subject":"Re: can I use multiple worktree in same git repo ?","fromName":"Sergio","fromEmail":"sergio.callegari@gmail.com","sentAt":"2011-07-22T09:06:44Z","receivedAt":"2011-07-22T09:06:44Z","isPatch":false,"sender":{"key":"sergio.callegari@gmail.com","avatar":"https://gravatar.com/avatar/c98f41317e0422c1e630385de0e3970227b8e5ad15f35ba8586066467cc833bc?d=mp&s=160"},"body":"Jakub Narebski <jnareb <at> gmail.com> writes:\n\n> \n> On Thu, 21 Jul 2011, Fredrik Gustafsson wrote:\n> > On Thu, Jul 21, 2011 at 11:17:57AM -0700, Jakub Narebski wrote:\n> \n> > > Actually with git-new-workdir you can have multiple working\n> > > directories associated with single repository, by the way of symlinks.\n> > > \n> > > Note however that if you intend to *work* in those workdirs, they\n> > > better correspond to different branches... or you can mess something\n> > > heavy.\n> > \n> > It would be possible to use the .git-file feature here. Then symlinks are\n> > avoided and the solution is portable.\n> \n> Actually it wouldn't.  Each new workdir has a separate HEAD and a\n> separate index; it is contents of .git that is symlinked, not .git\n> itself.\n> \n\nIs there any means to separate worktree info from the object repository? E.g., \nhaving a .git dir identical to that of a bare repo and a .git_workdir dir with \nthe head, head logs, index and all what makes a nonbare repo different from a \nbare one? That might make it easier to transform a repo from bare to nonbare in \naddition to simplifying the logic of git-new-workdir.\n"}]}