4
votes

I have a PhpStorm project linked to a remote server (a VM) where I set automatic deployment, so each time I modify and save a file, it is uploaded automatically to this server. Now I want to use GIT on this project. My workflow should be the following : - Work on local copy - Saving and automatic upload to the development server - Test (open webpage on dev server) - if ok, commit from local copy. Then push, etc...

My question is : how to work with branches ? I mean, I know that when switching branch, the directory I work on can completely change. Example : my branch A contains a.html. My branch B only contains b.html If I switch branch locally, the content of my folder will change. Will PhpStorm will add/delete a.html/b.html on my deployment server each time I switch branch ? Obviously, it's not what I want. How these changes will be reflected on the deployment server, how PhpStorm manage it ? Thank you for your help

4
(not an expert in VCS+Deployment here) Automatically: unlikely (even if it does: it potentially may create a mess). Better do it manually (I would): Tools | Deployment | Sync with Deployed.... In any case: there are few settings for automatic deployment in Settings | Deployment | Options (AFAIK the VCS operations are considered "external activities" so you should check that option). - LazyOne
Ok so PhpStorm doesn't offer a real solution for that kind of situation. To be able to test each branch, I'll have to upload in any case to the deployment server (so in different remote folder). To do so, I'll have to create a deployment server for each branch, and choose on which server I deploy ? Is it the best solution ? - Tinostarn
Sorry -- cannot really help here (not using VCSs myself ;( ). But .. if deployment for each branch has to be made into a different folder .. then yes -- either create multiple deployment entries and switch between them (or choose manually which one to use when manually syncing) .. or alter your default deployment entry each time (change target folder). As you can see there is no automation in this regard. If deployment will be made into the same folder -- then I do not really see any issues here (unless I've got you wrong). - LazyOne
Ok, if there's no automation or no better solution, I will opt for creating deployment entries each time I create a branch. But thinking back, I wonder if having a remote folder that changes all the time is really a problem, as long as I can test by opening my browser and have a fully functional environment. Any other suggestion is welcome :) - Tinostarn

4 Answers

1
votes

Just in case someone is looking for the solution:

Tools > Deployment > Options

Uncheck Skip external changes

Please Note: Option Automatic Upload (always) must be checked

0
votes

For something like this, you can approach a number of different ways. Here's a couple.

  1. set up a cron job on the server to regularly pull from master, then you would have to use branches for each new task and merge them when they are done, and the cron job will handle it on next pull of master.
  2. if you prefer to handle this in phpstorm, you can create a bash alias in your .bashrc or .bash_profile to ssh into the server and do a pull (I named my alias 'deploy'), then you can run the command in the built in terminal in phpstorm.

I prefer the second method as I don't have to wait for cron to do it's thing and I can see when an error occurs such as a merge conflict of some sort.

0
votes

I was able to solve this problem having an ssh window open with the remote environment. Just create a branch and do a checkout on the remote server. Now all the changes you upload via phpstorm will count as changes to that branch. You can still save and then view the results in your browser.

-1
votes

PHPStorm's GIT will only use your local copy. This hasn't anything to do with deployment. PHPStorm should not commit his own configuration files within the project. You can check this at Settings -> Version Control -> Ignored Files where it should say the .idea folder and a file ending with .iws. Ofcourse you could also add other files to ignore (like your own config files)

If you're using git in the CLI (not in PHPStorm) you should create a .gitignore file containing to ignore PHPStorm's config files:

/.idea
*.iws

PHPStorm should only sync branch-switches when Upload external changes is enabled in the deployment options since GIT is external.