1

In an EC2 AWS instance, I have a remote bare git repository created following:

@server:~$ mkdir -p /home/myuser/domain.git && chmod 770 /home/myuser/domain.git && cd /home/myuser/domain.git && git init --bare

With a post-receive hook:

@server:~$ nano hooks/post-receive

The hook script is:

#!/bin/sh
sudo git --work-tree=/var/www/domain --git-dir=/home/myuser/domain.git checkout -f

It has permission to execute:

@server:~$ chmod +x hooks/post-receive

I work on a local repo following:

@local:~$ 
    git init
    git remote add server server:/home/myuser/domain.git
    git checkout -b www-dev
    git add .
    git commit -am "Initial"

However, when I push changes:

@local:~$ git push server www-dev

The hook fails:

remote: fatal: You are on a branch yet to be born
To server:/home/myuser/domain.git
   06709ae..d1d7ead  www-dev -> www-dev

And the website is not updated. Why?

I suspect that the problem is caused by the fact that git checkout -f is called by the root. But only the root can write in /var/www/domain.

Medical physicist
  • 2,510
  • 4
  • 34
  • 51

1 Answers1

0

Awkward solution, you have to make your first push to the master branch:

@local:~$ 
    git init
    git remote add server server:/home/myuser/domain.git
    git add .
    git commit -am "Initial"
    git checkout -b www-dev
    git push server master

After that you can checkout to another branch:

@local:~$ git checkout -b www-dev

However there is another problem: it only deploys the master branch. The solution to this problem can be found here.

Community
  • 1
  • 1
Medical physicist
  • 2,510
  • 4
  • 34
  • 51