1

I'm desperately trying to prepare a correct environment for a new project. We plan to work locally with Xampp with my team and then push everything on a testing server, so I've started to learn git and its specificities.

When I try to push everything is ok, but then I want my server to automatically pull the updated files where it was cloned. So I created a post-update file which is like this.

#!/bin/bash

echo "Mise en production..."

cd /home/test/public_html/
unset GET_DIR

git fetch origin master

The problem is I get this error

remote: Mise en production...
remote: fatal: Not a git repository: '.'

Is there a better solution that would be efficient ?

Thanks everyone.

3615_Internet
  • 105
  • 1
  • 14
  • Invest some time into using CI tools like Jenkins and get your CI pipeline up and running to handle the builds. – Grinch91 Apr 21 '17 at 10:39
  • You could take a look at Git's hooks - https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks - which can perform actions in different states e.g. pre-commit, post-commit, etc – Emil Bækdahl Apr 21 '17 at 10:43
  • @Emil It looks like OP is in fact already using a hook, namely the post-receive one :-) – Just a student Apr 21 '17 at 10:47

2 Answers2

1

Your attempted solution works, but you have overlooked one detail.

When changing into /home/test/public_html/, you need to realize that this directory is not a Git repository and hence, you cannot fetch into it. To make this work, execute the following once.

$ cd /home/test/public_html
$ git init
$ git remote add origin [path/to/git/repo]

After that, you'll be able to git fetch and git pull in /home/test/public_html.

The [path/to/git/repo] should be a relative or absolute path to the directory that contains your repository. This is the directory that has directories branches, hooks, info, et cetera.

Just a student
  • 10,560
  • 2
  • 41
  • 69
0

It seems you need that after the local repo changes are pushed to a testing server, then you also want the local changes are pushed to your server. So you can use post-update hook to do that:

In the testing server, edit the contents of hooks/post-update file as below:

#!/bin/sh
echo "Mise en production..."
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
git push -u /path/for/your/server $branch
echo "push to my server "
Marina Liu
  • 36,876
  • 5
  • 61
  • 74