threads / discuss / 9067

Update a bare repository

Subject: Update a bare repository

## tl;dr

5 messages between Jul 17, 2007 and Jul 17, 2007.

replies: 4people: 2as markdown or json

Thomas Glanzmann· Jul 17, 2007, 06:30 UTC · lore

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· Jul 17, 2007, 07:04 UTC · re: Thomas Glanzmann · lore

Re: Update a bare repository

On Tue, Jul 17, 2007 at 08:30:26AM +0200, Thomas Glanzmann wrote:
Show 5 quoted lines
> 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· Jul 17, 2007, 07:26 UTC · re: Jeff King · lore

Re: Update a bare repository

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· Jul 17, 2007, 07:31 UTC · re: Thomas Glanzmann · lore

Re: Update a bare repository

On Tue, Jul 17, 2007 at 09:26:35AM +0200, Thomas Glanzmann wrote:
Show 5 quoted lines
> > 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· Jul 17, 2007, 07:41 UTC · re: Jeff King · lore

Re: Update a bare repository

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

← back to recent threads