# easy repository initialization that turned out not to be that easy

2 messages from 2007-07-25 to 2007-07-25. Participants: Steffen Prohaska, Johannes Schindelin.
Thread: https://gitlist.dev/t/9223

## Steffen Prohaska, 2007-07-25 20:05

Subject: easy repository initialization that turned out not to be that easy
Message-ID: <0EAD32C5-11DA-4B99-919D-87C0006A389C@zib.de>
URL: https://gitlist.dev/e/0EAD32C5-11DA-4B99-919D-87C0006A389C%40zib.de

```
I stumbled about some tasks that I expected to be easy but
turned out not to be that easy ...

(with git version 1.5.3.rc2.29.gc4640f)


1) How can I switch a private repository to shared as if it
was created by 'git-init --shared' in the first place?

Just executing 'git-init --shared' in the repo doesn't
adjust permissions as needed.

Cloning it to shared doesn't work either because the meaning
of 'git-clone --bare --shared' is different from
'git-init --shared'.

So I created a fresh repository

    mkdir shared.git
    cd shared.git
    git --bare init --shared

and tried to naively fetch all by executing

    git fetch ../private.git

Hmm... it does a lot of things, but I ended without branches.
fetch apparently has nothing like '--all'.

... but push has, so I finally did

    cd ../private.git
    git push --all ../shared.git
    git push --tags ../shared.git

Note, 'git push --all --tags' refused to work, so I needed
to push branches and tags separately.

Is it really that hard, or did I miss something?


2) How can I set up an empty bare repository that shares
objects with an existing repository? I'd like to do that
to save space and bandwidth.

I started to search for something like 'git init --reference'
or 'git init -l', similar to what 'git clone' provides.

I don't remember all approaches I tried, but finally I used

    git clone --bare -l existing.git new.git
    cd new.git
    mv refs/head/master .
    rm -rf refs/heads/* refs/tags/*
    mv master refs/heads

I remember that I needed to leave the master in place because
otherwise a 'git push' didn't recognize that objects are already
present and transferred everything, which is quite annoying over
a slower network connection. With master in place the first push
to new.git worked as expected. Only the additional objects were
sent.

Did I miss something?

	Steffen

```

## Johannes Schindelin, 2007-07-25 20:15

Subject: Re: easy repository initialization that turned out not to be that easy
Message-ID: <Pine.LNX.4.64.0707252112250.14781@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0707252112250.14781%40racer.site
In-Reply-To: <0EAD32C5-11DA-4B99-919D-87C0006A389C@zib.de>

```
Hi,

On Wed, 25 Jul 2007, Steffen Prohaska wrote:

> Cloning it to shared doesn't work either because the meaning of 
> 'git-clone --bare --shared' is different from 'git-init --shared'.

Yes, I lamented on that already.  But we cannot change that.  Too many 
users.

>    mkdir shared.git
>    cd shared.git
>    git --bare init --shared
> 
> and tried to naively fetch all by executing
> 
>    git fetch ../private.git

Almost.  "git fetch" does not store anything by default, so you have to do 
something like

	$ git config remote.origin.url ../private.git
	$ git config remote.origin.fetch 'refs/*:refs/*'
	$ git fetch

Eventually, I would like that to be available with

	$ git remote add --mirror fetch ../private.git

If nobody beats me to it, I'll do it later today.

Ciao,
Dscho

```
