threads / discuss / 24122

No working tree repository

Subject: No working tree repository

## tl;dr

8 messages between Jun 15, 2010 and Jun 16, 2010.

replies: 7people: 6as markdown or json

Phillip Susi· Jun 15, 2010, 17:56 UTC · lore

I'd like to keep a local copy of the kernel repository mainly for searching the history. The working tree uses up nearly 400mb of disk space that I do not normally need. How can I remove the working tree, and keep only the packed repository so I can review the logs, and only check out a working copy if I actually want to edit or compile the sources?

Matthieu Moy· Jun 15, 2010, 18:10 UTC · re: Phillip Susi · lore

Re: No working tree repository

Phillip Susi <psusi@cfl.rr.com> writes:
Show 6 quoted lines
> I'd like to keep a local copy of the kernel repository mainly for
> searching the history.  The working tree uses up nearly 400mb of disk
> space that I do not normally need.  How can I remove the working tree,
> and keep only the packed repository so I can review the logs, and only
> check out a working copy if I actually want to edit or compile the
> sources?

This is called a "bare" repository. Now, you have the keyword to RTFM ;-).

You can do something like

mv linux-repo linux-tree cd linux-tree mv .git ../linux-repo cd ../linux-repo git config core.bare true

(and optionnaly remove linux-tree/)

or you could have used "git clone --bare" when you cloned the repository.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Phillip Susi· Jun 15, 2010, 18:33 UTC · re: Matthieu Moy · lore

Re: No working tree repository

On 6/15/2010 2:10 PM, Matthieu Moy wrote:
> This is called a "bare" repository. Now, you have the keyword to
> RTFM ;-).
Ahh, that's the magic word I was groping for.

It seems that --bare on clone will prevent the checkout of the local working tree. If I decide I do want the sources today I can just check them out, but what is the proper way to do the reverse? I was thinking something like somehow empty the index file then do a git-reset or git-checkout-index to clean up the working tree to match the empty index, but I can't figure out how to empty the index.

Wesley J. Landaker· Jun 15, 2010, 20:41 UTC · re: Phillip Susi · lore

Re: No working tree repository

On Tuesday, June 15, 2010 12:33:32 Phillip Susi wrote:
Show 8 quoted lines
> Ahh, that's the magic word I was groping for.
> 
> It seems that --bare on clone will prevent the checkout of the local
> working tree.  If I decide I do want the sources today I can just check
> them out, but what is the proper way to do the reverse?  I was thinking
> something like somehow empty the index file then do a git-reset or
> git-checkout-index to clean up the working tree to match the empty
> index, but I can't figure out how to empty the index.

I often want to have a regular tree, but only sometimes check it out, and I want it to be in-place (e.g. not a bare repository and a separate work- tree).

What I do is I make a local "empty" branch with no files or ancestory. For this I have a "git-emptybranch" script (attached), but you can easily do this by hand.

Then when I want files, I do:
$ git checkout master  ## or whatever branch
When I'm done, I do
$ git checkout empty
and all the files go away.
Even with empty checked out, I can fetch, push, run gitk --all, etc.
This works well for me.
Matthieu Moy· Jun 15, 2010, 20:58 UTC · re: Phillip Susi · lore

Re: No working tree repository

Phillip Susi <psusi@cfl.rr.com> writes:
Show 12 quoted lines
> On 6/15/2010 2:10 PM, Matthieu Moy wrote:
>> This is called a "bare" repository. Now, you have the keyword to
>> RTFM ;-).
>
> Ahh, that's the magic word I was groping for.
>
> It seems that --bare on clone will prevent the checkout of the local
> working tree.  If I decide I do want the sources today I can just check
> them out, but what is the proper way to do the reverse?  I was thinking
> something like somehow empty the index file then do a git-reset or
> git-checkout-index to clean up the working tree to match the empty
> index, but I can't figure out how to empty the index.

rm -fr * # use at your own risk rm -f .git/index

Then, you can get back a tree with "git checkout" or "git checkout HEAD -- .". The advantage of this solution over the empty-branch solution is that although you destroyed your index, HEAD is still there so "git log" and friends will show you where you are.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Peter Krefting· Jun 16, 2010, 08:36 UTC · re: Phillip Susi · lore

Re: No working tree repository

Phillip Susi:
> It seems that --bare on clone will prevent the checkout of the local 
> working tree. If I decide I do want the sources today I can just check 
> them out, but what is the proper way to do the reverse?
Then I would recommend creating another clone. I usually do a
   git clone --reference path/to/bare server:path/to/origin newcheckout

to create clones with working trees, without having to pay the penalty of having (yet) another copy of the objects under .git (and with .git in the order of 400 megabytes, and several working copies, it does pay off).

Maintaining this is a lot easier than constantly adding and removing a working tree from the repository.

If you only need a single file, "git show commit:path" should work, even on a bare repository.

-- 
\\// Peter - http://www.softwolves.pp.se/
Andreas Schwab· Jun 15, 2010, 19:39 UTC · re: Matthieu Moy · lore

Re: No working tree repository

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 7 quoted lines
> You can do something like
>
> mv linux-repo linux-tree
> cd linux-tree
> mv .git ../linux-repo
> cd ../linux-repo
> git config core.bare true
Or shorter:
$ git clone --bare linux-repo

(which creates linux-repo.git and uses hardlinks, so it won't waste space)

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

← back to recent threads