# Update a bare repository

5 messages from 2007-07-17 to 2007-07-17. Participants: Thomas Glanzmann, Jeff King.
Thread: https://gitlist.dev/t/9067

## Thomas Glanzmann, 2007-07-17 06:30

Subject: Update a bare repository
Message-ID: <20070717063026.GA5823@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20070717063026.GA5823%40cip.informatik.uni-erlangen.de

```
Hello,
what I would like to do is the following:

I have a _bare_ clone of a git repository and would like to update it
from Junios repository at kernel.org from time to time.

How do I do that? In a way that it is a fire and forget solution? It
should also fetch new upstream branches.

"git pull" does not work. "git fetch" does, but it does update all
references?

	(faui02) [~/work/repositories/mirror/git.git] git pull
	fatal: /usr/bin/git-pull cannot be used without a working tree.
	(faui02) [~/work/repositories/mirror/git.git] git fetch
	(faui02) [~/work/repositories/mirror/git.git]

I also would like to check that it is impossible to push anything to the
repository.

		Thomas

```

## Jeff King, 2007-07-17 07:04

Subject: Re: Update a bare repository
Message-ID: <20070717070428.GA13266@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20070717070428.GA13266%40coredump.intra.peff.net
In-Reply-To: <20070717063026.GA5823@cip.informatik.uni-erlangen.de>

```
On Tue, Jul 17, 2007 at 08:30:26AM +0200, Thomas Glanzmann wrote:

> I have a _bare_ clone of a git repository and would like to update it
> from Junios repository at kernel.org from time to time.
> [...]
> "git pull" does not work. "git fetch" does, but it does update all
> references?

You don't want to pull because that involves merging, which doesn't make
sense. A git-fetch is what you want, and you can use wildcards to make
sure you get all of the refs. The default is something like this:

[remote "origin"]
  url = git://git2.kernel.org/pub/scm/git/git.git
  fetch = +refs/heads/*:refs/remotes/origin/*

However, if you are intending to make this an _exact_ copy of Junio's
(because you will be fetching from it with your other, non-bare repos),
then you probably don't want the "separate remotes" layout. You want to
copy the refs with the same names:

[remote "origin"]
  url = git://git2.kernel.org/pub/scm/git/git.git
  fetch = +refs/heads/*:refs/heads/*

The "+" in both cases means that it copies whatever Junio has, even if
it might lose some commits of yours. But that seems to be what you want
in this case.

> I also would like to check that it is impossible to push anything to the
> repository.

The simplest thing is not to give write access to the repo for your
pushers. However, you could also put in a pre-receive hook that rejects
all pushes.

-Peff

```

## Thomas Glanzmann, 2007-07-17 07:26

Subject: Re: Update a bare repository
Message-ID: <20070717072635.GG5823@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20070717072635.GG5823%40cip.informatik.uni-erlangen.de
In-Reply-To: <20070717070428.GA13266@coredump.intra.peff.net>

```
Hello,

> The "+" in both cases means that it copies whatever Junio has, even if
> it might lose some commits of yours. But that seems to be what you
> want in this case.

thanks a lot. That is exactly what I was looking for.

> The simplest thing is not to give write access to the repo for your
> pushers. However, you could also put in a pre-receive hook that rejects
> all pushes.

Is there an example somewhere?

	Thomas

```

## Jeff King, 2007-07-17 07:31

Subject: Re: Update a bare repository
Message-ID: <20070717073115.GA14629@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20070717073115.GA14629%40coredump.intra.peff.net
In-Reply-To: <20070717072635.GG5823@cip.informatik.uni-erlangen.de>

```
On Tue, Jul 17, 2007 at 09:26:35AM +0200, Thomas Glanzmann wrote:

> > The simplest thing is not to give write access to the repo for your
> > pushers. However, you could also put in a pre-receive hook that rejects
> > all pushes.
> 
> Is there an example somewhere?

Not that I know of, but it should be as simple as:

echo "echo Sorry, no pushing allowed.; exit 1" >.git/hooks/pre-receive
chmod +x .git/hooks/pre-receive

-Peff

```

## Thomas Glanzmann, 2007-07-17 07:41

Subject: Re: Update a bare repository
Message-ID: <20070717074112.GH5823@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20070717074112.GH5823%40cip.informatik.uni-erlangen.de
In-Reply-To: <20070717073115.GA14629@coredump.intra.peff.net>

```
Hello Peff,

> echo "echo Sorry, no pushing allowed.; exit 1" >.git/hooks/pre-receive
> chmod +x .git/hooks/pre-receive

thank you, that does exactly what I wanted:

	(faui03) [/var/tmp/git] git commit -a
	Created commit 9e89d1d: added some whitespace
	1 files changed, 1 insertions(+), 0 deletions(-)
	(faui03) [/var/tmp/git] git push origin
	updating 'refs/heads/master'
	from 9dfdf14b3805e89aa2782458bda15b3dfae24c09
	to   9e89d1d3890c6b0fd8546143a6e797820e274cb1
	Generating pack...
	Done counting 5 objects.
	Result has 3 objects.
	Deltifying 3 objects...
	100% (3/3) done
	Writing 3 objects...
	100% (3/3) done
	Total 3 (delta 2), reused 0 (delta 0)
	Sorry, no pushing allowed.
	error: hooks/pre-receive exited with error code 1
	ng refs/heads/master pre-receive hook declined
	error: failed to push to '131.188.30.103:/home/cip/adm/sithglan/work/repositories/mirror/git.git'

		Thomas

```
