¿Cómo puedo usar git para enviar a una carpeta específica en mi sitio?

Me gustaría hacer lo siguiente:

  • 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 a mysite.com/my-awesome-app

Can someone explain how I would set that up?

preguntado el 31 de julio de 12 a las 15:07

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. -

2 Respuestas

Usted puede hacer mysite.com/my-awesome-app a git repository and set receive.denyCurrentBranch en ello a 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.

Respondido 31 Jul 12, 15:07

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

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

Your second suggestion (to push to a bare repo on the server and use the update hook) was the direction I went. Este artículo sealed the deal and gave me the hand-holding I needed to implement it being a total git novice. - James

Frio. Me alegro de poder ser de ayuda. - Noufal Ibrahim

Is there a git repo at ~/mysite.com on your remote server? If so, like James y Nouval célebre, be careful, this sort of nesting can be problematic.

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

  1. Crea el my-awesome-app repo outside of ~/mysite.com (say at ~/my-awesome-app).
  2. Entonces crear un enlace simbólico de ~/my-awesome-app/ a ~/mysite.com/my-awesome-app.
  3. And, to be safe, add ~/mysite.com/my-awesome-app/ En el correo electrónico “Su Cuenta de Usuario en su Nuevo Sistema XNUMXCX”. ~/mysite.com/.gitignore file to exclude it from actions of the ~/mysite.com/ repositorio

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.

Por último, lo haría 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 método.

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


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/.

contestado el 23 de mayo de 17 a las 13:05

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

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.