Ramesh Pareek Ramesh Pareek -4 years ago 83
Git Question

Git Why changes do not reflect on remote repository?

I am trying to setup push to deploy on a vps (a digitalocean droplet), for this I created a repo and initiated it with


cd /var
mkdir demorepo && cd demorepo
mkdir demo.git && cd demo.git
git init --bare

Now, created a hook named
in hooks directory in the repo

git --work-tree=/var/www/demo --git-dir =/var/demorepo/demo.git checkout -f

set permissions using

chmod +x post-receive

On my local machine I created a new repo with
git init
in a folder
and added the remote repo as

git remote add live ssh://root@extragrip.in/var/demorepo/demo.git

The Problem
Now I created a new file in the local repo and pushed it using

git push live master

The push is successful, But the changes don't reflect on the remote repo.
what am I doing wrong?

Answer Source

To ensure hooks work properly you should "debug" them by executing the commands manually.

If/when you get them working manually then you can think about putting them into a hook script.

In this specific question I would expect the command to fail with this error message:

fatal: Not a git repository: '=/var/demorepo/demo.git'

The reason for this is that you've unintentionally added a space after the --git-dir parameter.

git --work-tree=/var/www/demo --git-dir =/var/demorepo/demo.git checkout -f
                                       +-- here

Remove that space and you should be good to go.

You could also remove the equal sign as the following two variants are the same:

--git-dir x

But you can't combine the two as in your case the equal sign is part of the path that git tries to locate, hence the error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download