2

I'd like to do the following:

  • Create a local git repo, let's call it ~/my-awesome-app
  • create a folder on my site, let's call it mysite.com/my-awesome-app
  • Be able to just push any changes I make on ~/my-awesome-app to mysite.com/my-awesome-app

Can someone explain how I would set that up?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
James
  • 641
  • 8
  • 17
  • possible duplicate of [Git serve: I would like it that simple](http://stackoverflow.com/questions/377213/git-serve-i-would-like-it-that-simple) – Matt Ball Jul 31 '12 at 14:20
  • I don't think it's it's a duplicate. This question is asking to deploy to a directory. The other is asking about serving repositories. – Noufal Ibrahim Jul 31 '12 at 14:43

2 Answers2

4

You can make mysite.com/my-awesome-app a git repository and set receive.denyCurrentBranch in it to ignore to allow pushing there but this is risky.

If I wanted to do this, I'd make a bare repository on my server which I could push my code into and then change the update hook to export the latest tree into mysite.com/my-awesome-app (and optionally restart the app). That way, the repository and the deployed copy are two different things.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • So would the bare repo be somewhere outside the public html? and the update hook would just copy whatever is pushed into that forward into into the public folder? Out of curiosity, why would the first option be risky? – James Jul 31 '12 at 14:55
  • It would be outside `public_html` and it would use `git archive` rather than just "copy" the code. The first would be risky because pushing to a non-bare repo will not update the working copy. You'd have to set this up manually and that means chances for bugs. – Noufal Ibrahim Jul 31 '12 at 17:53
  • Your second suggestion (to push to a bare repo on the server and use the update hook) was the direction I went. [This article](http://joemaller.com/990/a-web-focused-git-workflow/) sealed the deal and gave me the hand-holding I needed to implement it being a total git novice. – James Aug 02 '12 at 04:37
  • Cool. Glad I could be of help. – Noufal Ibrahim Aug 02 '12 at 04:42
1

Is there a git repo at ~/mysite.com on your remote server? If so, like James and Noufal noted, be careful, this sort of nesting can be problematic.

Consider the following solution that should work whether it's nested or not:

  1. Create the my-awesome-app repo outside of ~/mysite.com (say at ~/my-awesome-app).
  2. Then create a symbolic link from ~/my-awesome-app/ to ~/mysite.com/my-awesome-app.
  3. And, to be safe, add ~/mysite.com/my-awesome-app/ to the ~/mysite.com/.gitignore file to exclude it from actions of the ~/mysite.com/ repo.

On the remote server, from shell:

mkdir ~/my-awesome-app/
ln -s ~/my-awesome-app/ ~/mysite.com/my-awesome-app
echo /my-awesome-app >> ~/mysite.com/.gitignore

When releasing commits from the local my-awesome-app branch to the remote server, I would use the path ~/my-awesome-app as the upload/relative directory rather than ~/mysite.com/my-awesome-app. This should save you from some cheeky IDE that tries to ascend the file structure looking for git repos.

Lastly, I would consider adding a remote repo at ~/my-awesome-app and not just sending file there via sftp/ftp or ssh without a repoo. This allows you to maintain a highly stable production environment while still being able to incoporate hotfixes back into your local dev copy using the scalable gitflow method.

There's a good discussion on gitflow by Vincent Driessen here.


Update: Alternative approach to symbolic link

Instead of a symbolic link (which has the potential to be deleted), you could make the changes to your site's config instead:

# creates the alias
<IfModule mod_alias.c>
     Alias /my-awesome-app /path/to/my-awesome-app/
</IfModule>

# allows people to access the path
<Directory /path/to/my-awesome-app/>
        Order allow,deny
        Allow from all
</Directory>

Then when you do pushes, you should use /path/to/my-awesome-app/. I would still leave the /my-awesome-app line in ~/mysite.com/.gitignore just to be safe but without a symbolic link, git should never stumble accross the my-awesome-app repo at when acting on ~/mysite.com/.

Community
  • 1
  • 1
roberthernandez
  • 524
  • 3
  • 10
  • Thanks very much for this answer, much appreciated. I am weighing all the options and continuing my exploration and will be back after I've sussed it all out. – James Aug 01 '12 at 13:23