Git Branches: deploy to different locations


Hi there,

is it possible to deploy git branches to different servers?
For example:
Got a repo with 2 branches: develop and master.What I need is PhpStorm to deploy changes depending on the current branch to a specific server (branch master to and branch develop to

Please let me know if it's possible or if there exists a workaround for this problem!



I have similar request here for Python development.

I would like to use two different servers and interpreters in order to develop upgraded version of my project. New branch will use new python librairies on a more recent server. The other branch is maintained for bug fix on existing environement.



Deployment configs are stored in the .idea/deployment.xml file within the project. So It is possible to put different versions of the file to different branches, and then switching a branch will also switch the deployment settings.


Thank you for you swift answer.

I can see config file, but how can I make the link between branch and deployment file ?

Should I commit deployment.xml according to each branch ? Usually I ignore .idea/* files on Github.


> Should I commit deployment.xml according to each branch ?

Yes, that's the idea. Even if the .idea folder is ignored, you can force add this specific file.


Got it !  Thanks for the tip :)


We have a similar setup in our team: one repository with 2 branches ("dev" and "master") that should be deployed into two different folders on the dev-server ("html-dev" and "html-main")

but: every developer has his/her own dev-servers (mine is "dev-dunstheimer") , and the server-name is also stored in deployment.xml

how would I do this? :)


Andreas Dunstheimer

You can utilize synchronous repository control:

Init a repo in the .idea folder, add the same branches as you have in the main repo, and add the corresponding deployment.xml to them. So your project will have 2 repos - the main one with code, that is shared, and the local one with your .idea/deployment (and other configs if needed). 

Make sure the repo in the .idea folder is correctly recognized in the IDE, add a mapping in Settings | Version Control. Then enable Execute git operations on all branches in Settings | Version Control | Git.

This way, along with switching branch in the main repo the version of deployment.xml will be also switched.

This of course should be set up locally for everyone.


sounds promising - thanks for that quick answer ! 


"switching a branch will also switch the deployment settings."

The problem is the deployment settings are loaded into memory when PHP is loaded.  If you switch branches from within PHPStorm and it updates the deployment.xml file, those changes are not recognized unless you restart PHPStorm.

Does anybody know a way to update the deployment mappings after switching branches within PHPStorm without restarting PHPStorm?


Are you switching branch with PhpStorm or externally via Terminal?
If via Terminal, does File | Synchronize make it upload after branch switching?



Ignore my comment above.  I tested by manually changing the deployment.xml file and didn't see it update in PHPStorm.  I've since created the git repo for my .idea settings and it works as described.  Apparently when switching branches in PHPStorm it automatically refreshes the settings from the file system.  Thanks!

Thanks for this solution. It works reasonably well. Except I was confused when I could not get the simultaneous switch to work, when switching branches in Terminal tab with git checkout.
It took me a long time to figure out that the only way this works is by using the Git Branches window. When you checkout branches there, it works.
This is not very handy when you are used to using the Terminal for switching. And it is confusing that the state you left the Terminal is not reflecting the checked out branch.
I wish the simultaneous switch would also work when doing git checkout in the Terminal tab. Or that you could add deployment settings per branch more easily without this simultaneous, nested repo approach.
My main reason for looking for a solution was that on branch switch, whole directories are being deleted from the server and uploaded again if you have auto upload set, and 'skip external changes' off (because of file watchers). Even if nothing in the directory changed.  Very tedious to have to wait each time. 
My workaround now is a keyboard shortcut that toggles the auto upload. Toggle off before a branch change, and toggle on when switching back. I wish PHPstorm would recognise if no files were changed after a branch switch and not start deleting + uploading everything.