threads / discuss / 29860

git push from client is not updating files on server

Subject: git push from client is not updating files on server

## tl;dr

15 messages between Mar 6, 2012 and Mar 30, 2012.

replies: 14people: 5as markdown or json

Jerome Yanga· Mar 6, 2012, 16:52 UTC · lore

My main objective is to create a central public Git server. I had followed the instructions in the URL below to make it public.

http://book.git-scm.com/4_setting_up_a_public_repository.html
>From the git client server, I can successfully clone projects in from
the central public Git server using the command below.
git clone http://<hostname_of_central_public_git_server>/<Project_name>.git

My push seems to be successful too using the command below as I get the message "Everything up-to-date".

git push

However, when I log into the central public Git server and look at the files in the project, none of them have change. I can only see the changes from the client via Gitweb.

Help.

Regards, j

Ben Tebulin· Mar 6, 2012, 17:46 UTC · re: Jerome Yanga · lore

Re: git push from client is not updating files on server

You can only push to "bare-only repositories". These do not contain a working tree but only a .git directory.

You can only see changes changes in Git repository on the file system if you clone & pull this bare-only repository to a regular repository.

It seems you looking for the wrong thing in the wrong place...
Am 06.03.2012 17:52, schrieb Jerome Yanga:
> My main objective is to create a central public Git server.
 > [...]
> However, when I log into the central public Git server and look at the
> files in the project, none of them have change.  I can only see the
> changes from the client via Gitweb.
Junio C Hamano· Mar 6, 2012, 19:35 UTC · re: Ben Tebulin · lore

Re: git push from client is not updating files on server

[jc: resurrected JY as recipient]
Ben Tebulin <nntp.20.jexpert@spamgourmet.com> writes:
> You can only push to "bare-only repositories". These do not contain a
> working tree but only a .git directory.

That's a bit too strong. You do not have to limit your "push" into "bare repositories" (drop "-only", there is no such word), but it is perfectly fine to use "push" as a way to emulate a "fetch" that you would wish you could but you cannot in the opposite direction.

What "push" does not do is to touch the working tree, and this is intuitively understandable once you realize that "push" is an opposite of "fetch".

> My push seems to be successful too using the command below as I get
> the message "Everything up-to-date".
> 
> git push
It is somewhat strange that this _succeeded_.

When pushing into a repository with a working tree (i.e. "a non-bare repository") and especially when trying to update its current branch with such a push, "git push" would by default be refused, unless you tweak a configuration variable or two on the receiving end. That is an expert feature and I do not think that is being in use in this particular scenario, so perhaps the push did _not_ succeed to update the branch Jerome thought it updated, but instead updated a branch that is _not_ the one that is checked out in the repository on the receiving end of this push.

Neal Kreitzinger· Mar 6, 2012, 21:12 UTC · re: Jerome Yanga · lore

Re: git push from client is not updating files on server

On 3/6/2012 10:52 AM, Jerome Yanga wrote:
Show 20 quoted lines
> My main objective is to create a central public Git server.  I had
> followed the instructions in the URL below to make it public.
>
> http://book.git-scm.com/4_setting_up_a_public_repository.html
>
> From the git client server, I can successfully clone projects in
> from the central public Git server using the command below.
>
> git clone
> http://<hostname_of_central_public_git_server>/<Project_name>.git
>
> My push seems to be successful too using the command below as I get
> the message "Everything up-to-date".
>
> git push
>
> However, when I log into the central public Git server and look at
> the files in the project, none of them have change.  I can only see
> the changes from the client via Gitweb.
>

Gitweb and gitk know how to look at .git (bare) repo and display the contents. (I use gitk to verify that a push did what I wanted.) There is no work-tree for a .git repo to do linux "ls" on. If you really want to use commandline you would have to use git commands like git-show, git-ls-files, git-cat-file, git-log, etc., to display and interrogate the contents of git objects (tags, commits, trees, blobs) in a .git repo.

I suspect reviewing it in gitweb is sufficient to verify that the push did what you wanted. (I don't use gitwet, yet.)

v/r, neal

Neal Kreitzinger· Mar 6, 2012, 21:21 UTC · re: Neal Kreitzinger · lore

Re: git push from client is not updating files on server

On 3/6/2012 3:12 PM, Neal Kreitzinger wrote:
Show 12 quoted lines
> On 3/6/2012 10:52 AM, Jerome Yanga wrote:
>>
>> However, when I log into the central public Git server and look at
>> the files in the project, none of them have change. I can only see
>> the changes from the client via Gitweb.
>>
> Gitweb and gitk know how to look at .git (bare) repo and display the
> contents. (I use gitk to verify that a push did what I wanted.) There is
> no work-tree for a .git repo to do linux "ls" on. If you really want to
> use commandline you would have to use git commands like git-show,
> git-ls-files, git-cat-file, git-log, etc., to display and interrogate
> the contents of git objects (tags, commits, trees, blobs) in a .git repo.

scratch git-ls-files from that list. Its not much use for bare repos, either.

v/r, neal

Junio C Hamano· Mar 6, 2012, 20:37 UTC · lore

Re: git push from client is not updating files on server

Jerome Yanga <jerome.yanga@gmail.com> writes:

[jc: kicking the thread back to the list; I do not give free consultation in private, but I do not mind answering questions in public to help wider audience.]

Show 12 quoted lines
> Thank you for the prompt response.
>
> The projects in the Apache DocumentRoot are bare repositories.  I
> think this is what allowed me to push at least this is how I
> understood it from the URL I had quoted in my last message.
>
> If I understood what you had said about push being the opposite of
> fetch, then it is understandable that the files on the working
> directory did not get updated and that it only shows in the Gitweb
> interface.
>
> So how do I make the changes go in the working tree?

By arranging a "checkout" to happen when you want to. One common way people seem to do this is to have "git reset --hard HEAD" in post update hook when the push came to the current branch, assuming that nobody but the update in response to "push" is expected to touch the working tree of the receiving repository.

Jerome Yanga· Mar 6, 2012, 23:07 UTC · lore

Re: git push from client is not updating files on server

Is there a way to make git write to the working directory of the central public server?

Please be nice to the newbee.  I am merely learning Git.

Regards, j

On Tue, Mar 6, 2012 at 3:05 PM, Jerome Yanga <jerome.yanga@gmail.com> wrote:
Show 35 quoted lines
> Please be nice to the newbee.  I am merely learning Git.
>
> Regards,
> j
>
> On Tue, Mar 6, 2012 at 3:02 PM, Jerome Yanga <jerome.yanga@gmail.com> wrote:
>> Is there a way to make git write to the working directory of the
>> central public server?
>>
>> Regards,
>> j
>>
>> On Tue, Mar 6, 2012 at 1:21 PM, Neal Kreitzinger <nkreitzinger@gmail.com> wrote:
>>> On 3/6/2012 3:12 PM, Neal Kreitzinger wrote:
>>>>
>>>> On 3/6/2012 10:52 AM, Jerome Yanga wrote:
>>>>>
>>>>>
>>>>> However, when I log into the central public Git server and look at
>>>>> the files in the project, none of them have change. I can only see
>>>>> the changes from the client via Gitweb.
>>>>>
>>>> Gitweb and gitk know how to look at .git (bare) repo and display the
>>>> contents. (I use gitk to verify that a push did what I wanted.) There is
>>>> no work-tree for a .git repo to do linux "ls" on. If you really want to
>>>> use commandline you would have to use git commands like git-show,
>>>> git-ls-files, git-cat-file, git-log, etc., to display and interrogate
>>>> the contents of git objects (tags, commits, trees, blobs) in a .git repo.
>>>
>>>
>>> scratch git-ls-files from that list.  Its not much use for bare repos,
>>> either.
>>>
>>> v/r,
>>> neal
Neal Kreitzinger· Mar 6, 2012, 23:32 UTC · re: Jerome Yanga · lore

Re: git push from client is not updating files on server

On 3/6/2012 5:07 PM, Jerome Yanga wrote:
> Is there a way to make git write to the working directory of the
> central public server?
>
In your original post you stated:
 > From the git client server, I can successfully clone projects in from
 > the central public Git server using the command below.
 >
 > git clone 
http://<hostname_of_central_public_git_server>/<Project_name>.git

".git" extension implies "bare" repo. A bare repo has _no_ working tree. Is the repo in question bare or non-bare? If you are not sure, then cd to the central-repo-dir (ie., the <Project_name>.git you cloned _from_ in your example above) and run "git config -l |grep bare". If it says "core.bare=true" then it is a bare repo.

v/r, neal

Jerome Yanga· Mar 7, 2012, 00:28 UTC · re: Neal Kreitzinger · lore

Re: git push from client is not updating files on server

The project in Apache's DocumentRoot was created using the following command:

"cd /var/www/git git clone --bare <non-bare working directory> <project>.git"

Hence, I believe that is is bare. Besides, it does not have .git folder. I assumed that when I did this that the non-bare directory will also be updated when a push is performed via http.

My objective is that I would like the developers to be able to push via http and these pushes will need to be reflected on the non-bare working directory as these directories will be used for automated tests.

Is what I am trying to do even possible?  If so, please share with me a guide.
Thank you in advance.

Regards, j

On Tue, Mar 6, 2012 at 3:32 PM, Neal Kreitzinger <nkreitzinger@gmail.com> wrote:
Show 22 quoted lines
> On 3/6/2012 5:07 PM, Jerome Yanga wrote:
>>
>> Is there a way to make git write to the working directory of the
>> central public server?
>>
> In your original post you stated:
>
>
>> From the git client server, I can successfully clone projects in from
>> the central public Git server using the command below.
>>
>> git clone
>> http://<hostname_of_central_public_git_server>/<Project_name>.git
>
> ".git" extension implies "bare" repo.  A bare repo has _no_ working tree.
>  Is the repo in question bare or non-bare?  If you are not sure, then cd to
> the central-repo-dir (ie., the <Project_name>.git you cloned _from_ in your
> example above) and run "git config -l |grep bare".  If it says
> "core.bare=true" then it is a bare repo.
>
> v/r,
> neal
Neal Kreitzinger· Mar 7, 2012, 01:11 UTC · re: Jerome Yanga · lore

Re: git push from client is not updating files on server

On 3/6/2012 6:28 PM, Jerome Yanga wrote:
Show 5 quoted lines
> The project in Apache's DocumentRoot was created using the following command:
>
> "cd /var/www/git
> git clone --bare<non-bare working directory>  <project>.git"
>
I have a comment on the above command.  Did you run:
git clone --bare /non-bare/working/directory project.git
(or)
git clone --bare file:///non-bare/working/directory project.git

because the former does hardlinks and the latter does a full copy (see git-clone manpage section "GIT URLS"). I'm not sure how much it matters, but you should confirm whether what you did is what you want.

v/r, neal

Junio C Hamano· Mar 7, 2012, 02:23 UTC · re: Jerome Yanga · lore

Re: git push from client is not updating files on server

Jerome Yanga <jerome.yanga@gmail.com> writes:
Show 13 quoted lines
> The project in Apache's DocumentRoot was created using the following command:
>
> "cd /var/www/git
> git clone --bare <non-bare working directory> <project>.git"
>
> Hence, I believe that is is bare.  Besides, it does not have .git
> folder.  I assumed that when I did this that the non-bare directory
> will also be updated when a push is performed via http.
>
> My objective is that I would like the developers to be able to push
> via http and these pushes will need to be reflected on the non-bare
> working directory as these directories will be used for automated
> tests.

So that <non-bare working directory> above is what you want to be updated when you update <project>.git?

More concretely, for example, you have say /srv/project/frotz and /var/www/git/frotz.git directories on that server. Perhaps the project may have started in the former:

	mkdir -p /srv/project/frotz
        cd /srv/project/frotz
        git init
        ... populate with the sources ...
        git add ...
        git commit
and then cloned to the other one
	cd /var/www/git && git clone --bare /srv/project/frotz frotz.git
I'll assume that is more or less the set-up you have.

Now, it depends on how the push goes to the latter one (I do not remember offhand if pushing over dumb http transport triggers hooks), but in general, you would install a post-update hook (read githooks manual page) in the latter repository, that gets triggered when it receives a push. The hook could do something like this:

	#!/bin/sh
        unset GIT_DIR
        cd /srv/project/frotz &&
        git pull --ff-only /var/www/git/frotz.git master &&
	: you can trigger automated test here if you want to &&
        make test

The above example goes to the repository with a working tree, pulls the latest change from the repository the user pushed into, and then runs the automated test.

Neal Kreitzinger· Mar 7, 2012, 02:34 UTC · re: Jerome Yanga · lore

Re: git push from client is not updating files on server

On 3/6/2012 6:28 PM, Jerome Yanga wrote:
Show 7 quoted lines
> The project in Apache's DocumentRoot was created using the following command:
>
> "cd /var/www/git
> git clone --bare<non-bare working directory>  <project>.git"
>
> Hence, I believe that is is bare.  Besides, it does not have .git
> folder.

The bare repo is the .git folder. That's why its called barerepo.git. .git = git repo. worktree/.git = non-bare repo with worktree and .git repo. barerepo.git = bare repo and no worktree.

> I assumed that when I did this that the non-bare directory
> will also be updated when a push is performed via http.
>

The non-bare you cloned from is independent. It doesn't know about the bare repo you cloned from it, and your bare repo does not know about the non-bare repo it was cloned from. I'm not sure what you were doing with that non-bare before you created the bare from it. You may not need that non-bare anymore if that's all it was for.

Show 5 quoted lines
> My objective is that I would like the developers to be able to push
> via http and these pushes will need to be reflected on the non-bare
> working directory as these directories will be used for automated
> tests.
>

Create a new non-bare clone of your bare repo. Then do git-pull on the new non-bare after the bare gets updates (someone does git push to it) and you want to test those new commits. The worktree of the new non-bare clone can be the document root of your testing virtual host, if that's what you're doing. That way, you know that no one else is messing with new non-bare (test repo) like doing development in it and messing up your tests.

v/r, neal

Holger Hellmuth· Mar 7, 2012, 11:04 UTC · re: Neal Kreitzinger · lore

Re: git push from client is not updating files on server

On 07.03.2012 03:34, Neal Kreitzinger wrote:
Show 7 quoted lines
> Create a new non-bare clone of your bare repo. Then do git-pull on the
> new non-bare after the bare gets updates (someone does git push to it)
> and you want to test those new commits. The worktree of the new non-bare
> clone can be the document root of your testing virtual host, if that's
> what you're doing. That way, you know that no one else is messing with
> new non-bare (test repo) like doing development in it and messing up
> your tests.

To expand on Neals method, if you do git fetch (periodically in a cron job for example) on the cloned non-bare, 'git log HEAD..origin/HEAD' will have output only if the non-bare has new commits.

Jerome Yanga· Mar 7, 2012, 15:43 UTC · re: Holger Hellmuth · lore

Re: git push from client is not updating files on server

Thank you all for the recommendations.  I will try them.
I would like to confirm some info.
Junio,

Your assumption of my setup correct. I shall read on post-update hook. If you have a recommended link for it, please share it.

Neal,

You are also correct. My current configuration's reaction to a push shows that the bare repo that was cloned from a non-bare repo are independent of each other. I will also try your recommendation.

Holger,
Thank you for explaining what Neal meant.

Regards, j

On Wed, Mar 7, 2012 at 3:04 AM, Holger Hellmuth <hellmuth@ira.uka.de> wrote:
Show 16 quoted lines
> On 07.03.2012 03:34, Neal Kreitzinger wrote:
>>
>> Create a new non-bare clone of your bare repo. Then do git-pull on the
>> new non-bare after the bare gets updates (someone does git push to it)
>> and you want to test those new commits. The worktree of the new non-bare
>> clone can be the document root of your testing virtual host, if that's
>> what you're doing. That way, you know that no one else is messing with
>> new non-bare (test repo) like doing development in it and messing up
>> your tests.
>
>
> To expand on Neals method, if you do git fetch (periodically in a cron job
> for example) on the cloned non-bare, 'git log HEAD..origin/HEAD' will have
> output only if the non-bare has new commits.
>
>
Jerome Yanga· Mar 30, 2012, 18:23 UTC · re: Jerome Yanga · lore

Re: git push from client is not updating files on server

I finally got the chance to implement your suggestions. I have combined them and am very happy with the outcome. The missing pieces for being able to push via Apache are as follows:

01)  git config --global http.receivepack true (thanks Junio...found
this under githooks)
02)  chown -R apache:apache /var/www/git

On the other hand, I have also implemented a non-bare repo for testing (thanks Neal and Holger) by cloning the bare repo.

I hope that this helps another.  ;)

Regards, j

On Wed, Mar 7, 2012 at 7:43 AM, Jerome Yanga <jerome.yanga@gmail.com> wrote:
Show 39 quoted lines
> Thank you all for the recommendations.  I will try them.
>
> I would like to confirm some info.
>
> Junio,
>
> Your assumption of my setup correct.  I shall read on post-update
> hook.  If you have a recommended link for it, please share it.
>
> Neal,
>
> You are also correct.  My current configuration's reaction to a push
> shows that the bare repo that was cloned from a non-bare repo are
> independent of each other.  I will also try your recommendation.
>
> Holger,
>
> Thank you for explaining what Neal meant.
>
> Regards,
> j
>
> On Wed, Mar 7, 2012 at 3:04 AM, Holger Hellmuth <hellmuth@ira.uka.de> wrote:
>> On 07.03.2012 03:34, Neal Kreitzinger wrote:
>>>
>>> Create a new non-bare clone of your bare repo. Then do git-pull on the
>>> new non-bare after the bare gets updates (someone does git push to it)
>>> and you want to test those new commits. The worktree of the new non-bare
>>> clone can be the document root of your testing virtual host, if that's
>>> what you're doing. That way, you know that no one else is messing with
>>> new non-bare (test repo) like doing development in it and messing up
>>> your tests.
>>
>>
>> To expand on Neals method, if you do git fetch (periodically in a cron job
>> for example) on the cloned non-bare, 'git log HEAD..origin/HEAD' will have
>> output only if the non-bare has new commits.
>>
>>

← back to recent threads