# how to add files/folder from work-tree

5 messages from 2011-07-19 to 2011-07-20. Participants: J. Bakshi, Chris Packham.
Thread: https://gitlist.dev/t/27851

## J. Bakshi, 2011-07-19 06:30

Subject: how to add files/folder from work-tree
Message-ID: <20110719120048.3dd56eb6@shiva.selfip.org>
URL: https://gitlist.dev/e/20110719120048.3dd56eb6%40shiva.selfip.org

```
Hello,

I am using a git repo which has detached work tree. I like to add the files, folders located at the work tree ( it is a site under htdocs) at the git repo. Is it possible to do it within the work-tree or I need a separate working space from where I need to do all these operation ?

Thanks
 

```

## Chris Packham, 2011-07-19 08:13

Subject: Re: how to add files/folder from work-tree
Message-ID: <4E253C94.7000709@gmail.com>
URL: https://gitlist.dev/e/4E253C94.7000709%40gmail.com
In-Reply-To: <20110719133633.0797713d@shiva.selfip.org>

```
Oops managed to drop the Cc for the mailing list from my initial response.

On 19/07/11 20:06, J. Bakshi wrote:
> On Tue, 19 Jul 2011 19:53:28 +1200
> Chris Packham <judge.packham@gmail.com> wrote:
> 
>> On 19/07/11 18:30, J. Bakshi wrote:
>>> Hello,
>>>
>>> I am using a git repo which has detached work tree. I like to add the files, folders located at the work tree ( it is a site under htdocs) at the git repo. Is it possible to do it within the work-tree or I need a separate working space from where I need to do all these operation ?
>>>
>>> Thanks
>>>  
>>> --
>>
>> I'm not sure I fully understand your question but what I _think_ you
>> want to do is specify the path to the repository with the GIT_DIR
>> environment variable. Like this
>>
>>  cd /place/where/files/are
>>  GIT_DIR=/place/were/repo/is/.git git add <file>
>>
> 
> 
> I have set a git repo with attached work-tree with hook as below
> 
> git -bare init  /home/git/test.git
> cd /home/git/test.git
> git config core.worktree /var/www/test
> 
> vim /home/git/test.git/hooks/post-receive
> 
> #!/bin/sh
> git checkout -f
> 
> Now the /var/www/test has already some files/folder. How can I add those to the repo within from its work-tree ?
> 
> Thanks

I think my initial response is correct. Try the following

  cd /var/www/test
  git --git-dir=/home/git/test.git add <files>
  git --git-dir=/home/git/test.git commit -m "blah"

```

## J. Bakshi, 2011-07-19 08:22

Subject: Re: how to add files/folder from work-tree
Message-ID: <20110719135224.52c4301d@shiva.selfip.org>
URL: https://gitlist.dev/e/20110719135224.52c4301d%40shiva.selfip.org
In-Reply-To: <4E253C94.7000709@gmail.com>

```
On Tue, 19 Jul 2011 20:13:08 +1200
Chris Packham <judge.packham@gmail.com> wrote:

> Oops managed to drop the Cc for the mailing list from my initial response.
> 
> On 19/07/11 20:06, J. Bakshi wrote:
> > On Tue, 19 Jul 2011 19:53:28 +1200
> > Chris Packham <judge.packham@gmail.com> wrote:
> > 
> >> On 19/07/11 18:30, J. Bakshi wrote:
> >>> Hello,
> >>>
> >>> I am using a git repo which has detached work tree. I like to add the files, folders located at the work tree ( it is a site under htdocs) at the git repo. Is it possible to do it within the work-tree or I need a separate working space from where I need to do all these operation ?
> >>>
> >>> Thanks
> >>>  
> >>> --
> >>
> >> I'm not sure I fully understand your question but what I _think_ you
> >> want to do is specify the path to the repository with the GIT_DIR
> >> environment variable. Like this
> >>
> >>  cd /place/where/files/are
> >>  GIT_DIR=/place/were/repo/is/.git git add <file>
> >>
> > 
> > 
> > I have set a git repo with attached work-tree with hook as below
> > 
> > git -bare init  /home/git/test.git
> > cd /home/git/test.git
> > git config core.worktree /var/www/test
> > 
> > vim /home/git/test.git/hooks/post-receive
> > 
> > #!/bin/sh
> > git checkout -f
> > 
> > Now the /var/www/test has already some files/folder. How can I add those to the repo within from its work-tree ?
> > 
> > Thanks
> 
> I think my initial response is correct. Try the following
> 
>   cd /var/www/test
>   git --git-dir=/home/git/test.git add <files>
>   git --git-dir=/home/git/test.git commit -m "blah"
> 
> 

Great !! Thanks 

```

## J. Bakshi, 2011-07-20 10:16

Subject: Re: how to add files/folder from work-tree
Message-ID: <20110720154644.67974a7f@shiva.selfip.org>
URL: https://gitlist.dev/e/20110720154644.67974a7f%40shiva.selfip.org
In-Reply-To: <4E253C94.7000709@gmail.com>

```
On Tue, 19 Jul 2011 20:13:08 +1200
Chris Packham <judge.packham@gmail.com> wrote:

> Oops managed to drop the Cc for the mailing list from my initial response.
> 
> On 19/07/11 20:06, J. Bakshi wrote:
> > On Tue, 19 Jul 2011 19:53:28 +1200
> > Chris Packham <judge.packham@gmail.com> wrote:
> > 
> >> On 19/07/11 18:30, J. Bakshi wrote:
> >>> Hello,
> >>>
> >>> I am using a git repo which has detached work tree. I like to add the files, folders located at the work tree ( it is a site under htdocs) at the git repo. Is it possible to do it within the work-tree or I need a separate working space from where I need to do all these operation ?
> >>>
> >>> Thanks
> >>>  
> >>> --
> >>
> >> I'm not sure I fully understand your question but what I _think_ you
> >> want to do is specify the path to the repository with the GIT_DIR
> >> environment variable. Like this
> >>
> >>  cd /place/where/files/are
> >>  GIT_DIR=/place/were/repo/is/.git git add <file>
> >>
> > 
> > 
> > I have set a git repo with attached work-tree with hook as below
> > 
> > git -bare init  /home/git/test.git
> > cd /home/git/test.git
> > git config core.worktree /var/www/test
> > 
> > vim /home/git/test.git/hooks/post-receive
> > 
> > #!/bin/sh
> > git checkout -f
> > 
> > Now the /var/www/test has already some files/folder. How can I add those to the repo within from its work-tree ?
> > 
> > Thanks
> 
> I think my initial response is correct. Try the following
> 
>   cd /var/www/test
>   git --git-dir=/home/git/test.git add <files>

But this response as

ˋˋˋ`
fatal: This operation must be run in a work tree
ˋˋˋˋˋˋˋˋˋ

```

## J. Bakshi, 2011-07-20 10:52

Subject: Re: how to add files/folder from work-tree
Message-ID: <20110720162208.3fa89d8b@shiva.selfip.org>
URL: https://gitlist.dev/e/20110720162208.3fa89d8b%40shiva.selfip.org
In-Reply-To: <20110720154644.67974a7f@shiva.selfip.org>

```
On Wed, 20 Jul 2011 15:46:44 +0530
"J. Bakshi" <joydeep@infoservices.in> wrote:

> On Tue, 19 Jul 2011 20:13:08 +1200
> Chris Packham <judge.packham@gmail.com> wrote:
> 
> > Oops managed to drop the Cc for the mailing list from my initial response.
> > 
> > On 19/07/11 20:06, J. Bakshi wrote:
> > > On Tue, 19 Jul 2011 19:53:28 +1200
> > > Chris Packham <judge.packham@gmail.com> wrote:
> > > 
> > >> On 19/07/11 18:30, J. Bakshi wrote:
> > >>> Hello,
> > >>>
> > >>> I am using a git repo which has detached work tree. I like to add the files, folders located at the work tree ( it is a site under htdocs) at the git repo. Is it possible to do it within the work-tree or I need a separate working space from where I need to do all these operation ?
> > >>>
> > >>> Thanks
> > >>>  
> > >>> --
> > >>
> > >> I'm not sure I fully understand your question but what I _think_ you
> > >> want to do is specify the path to the repository with the GIT_DIR
> > >> environment variable. Like this
> > >>
> > >>  cd /place/where/files/are
> > >>  GIT_DIR=/place/were/repo/is/.git git add <file>
> > >>
> > > 
> > > 
> > > I have set a git repo with attached work-tree with hook as below
> > > 
> > > git -bare init  /home/git/test.git
> > > cd /home/git/test.git
> > > git config core.worktree /var/www/test
> > > 
> > > vim /home/git/test.git/hooks/post-receive
> > > 
> > > #!/bin/sh
> > > git checkout -f
> > > 
> > > Now the /var/www/test has already some files/folder. How can I add those to the repo within from its work-tree ?
> > > 
> > > Thanks
> > 
> > I think my initial response is correct. Try the following
> > 
> >   cd /var/www/test
> >   git --git-dir=/home/git/test.git add <files>
> 
> But this response as
> 
> ˋˋˋ`
> fatal: This operation must be run in a work tree
> ˋˋˋˋˋˋˋˋˋ

OK, need to append also --work-tree=/var/www/test

```
