Getting Auto Git plugin to work


#1

Hi,

I’m trying to switch from syncing my server with my local computer via FTP to using Git and SSH. And most of the things I wanted are working except for the Auto Git plugin. But I’m pretty sure it is my fault. Here’s what I’ve done so far:

  1. Setting up a local repository using Tower on my Mac.
  2. Establishing an SSH connection to my server.
  3. Creating a bare repo on the server with git init --bare .git
  4. Adding post-receive a hook like described in this guide.
  5. Back on my Mac, adding the remote repo to my local one using Tower.

The result is that I can push any changes I commit on my Mac using Tower to the remote. If I run the site locally using MAMP and make some changes in the Panel the Auto Git plugin even makes a commit to the local repository and I can push it to the remote server. However when I log in to the Panel on my server (i.e. not locally) and make some changes Auto Git doesn’t commit them and the widget says that there is no remote found.

Can anybody tell what I did wrong. I have a slight guess that it might has to do with the fact that on the server there is only a bare repo. When connected via SSH and I make some changes live on the server I can’t commit them either an Git says

fatal: This operation must be run in a work tree 

So it might be a problem in my configuration. But what can I do to fix it …?

Thanks in advance and cheers,
Tobi


#2

The problem is the bare repo. A bare repo is not made for editing, it doesn’t have a working tree. If you want to make changes on the server, you have to initialise a standard repo.


#3

That what I thought, I even tried to use git init before my experiments with Kirby but in that case I was unable to publish my master branch to the sever, although the remote was shown without any branches in Tower … is there an extra step I have to make?


#4

I usually push to Bitbucket, Gitlab, GitHub and then do a pull on the server instead of directly pushing to the remote server. This can also be automated (web hook, cronjob)


#5

So you have three repos that sync each other?!

your machine :left_right_arrow:︎ Bitbucket :left_right_arrow:︎ web server

could you explain how the sever syncs (pulls and pushes) from bitbucket? And is there a reason for using a Git provider in the middle?

Update
I made another test with a non-bare repo on the server: Connected via SSH I can create/change files in the servers repo and commit them. However when I add this as a remote in Tower (my local repo) I cannot push to the server since pushing to the checked out branch is denied (server runs git version 2.1.4). So I guess it must be a bare repo on the server. But then I cannot make changes on the server-side (via the Panel).


#6

Yes, I’m using three repos. The advantage is, that the repo in the middle also serves as a backup, so I can happily mess up everything locally and my server can get hacked and I still have my thing in the middle…

I haven’t had a need to automate the pull from the provider based repo to the remote server repo yet, so I used to do that manually - push to the provider based repo from local, ssh onto server, pull from remote, so I can’t provide a little tutorial.

I can’t really remember if I ever directly pushed to a remote that was not a cloud service. But there seems to be a git setting, see this answer on SO:


#7

Thanks for the link to SO, unfortunately the solutions given there require a higher version of git, that the one running on my VPS …

I’ll try to set up the server-in-the middle solution, I hope I can get it to work …

Thanks and cheers,
Tobi


#8

Can’t you update your Git version? If you run a VPS, you have full control of the server, don’t you?


#9

Hm … actually I know nearly nothing about how to set up servers etc. Maybe I’m even using the VPS term wrong. However I wrote my provider asking for a higher version and they said they plan an update in summer maybe. I guess he would have told me if I could update myself …