Changing git branch on remote server

已回答

I've cloned a git repo to my local dev machine, and did the same on my remote deployment server. I setup automatic upload of any local changes (on save). However, I just noticed that when I do git pull locally, or switch branches locally, these changes are not reflected on my deployment server.

Is there a way to configure such git integration?

1

And why do you use git on a deployment server at all? 

Basically, you do not need any versioning on the deployment server, you just need a copy of the code in your working directory.

This is exactly what the Deployment feature does. Note that external git client is used for git integration, so changes done by git are external for the IDE - thus you need to enable the Upload external in Deployment Options

-4
Avatar
Permanently deleted user

Thanks Dmitriy, I guess "Upload external changes" option helps to achieve this.

However the difference between branches might be significant (in my case, dozens of files, with potentially large files needed to be copied or deleted when switching). It seems to me that having PyCharm send a single "git checkout branchname' command instead of trying to sync the entire local repo state would be much more efficient.

Having identical git state on both local and remote machines seems to be a cleaner, more elegant solution. Are there any downsides to this approach?

1

Synchronizing via git is far more complicated.

Now, IDE just syncs whatever files it has in the project directory to the remote location, specified in settings. It is sImple and VCS-independent and allows handling all kind of changes - manual, VCS checkout, external copying, etc... It allows you to test changes on a deployment server before actually committing them.

The git-related approach will actually provide only one advantage - potentially less traffic between hosts. On the other hand, I  see the following drawbacks:

  1. The feature is VCS specific, however, does not fit the Git Integration in general. So this will probably need a separate plugin or special logic in the Deployment.
  2. It is more elegant only in case of branch switch, assuming the repo state on the remote is the same as yours. But if you have some changes you want to get to the remote, you have to commit them first, then push. It is even more complicated if you use a central repo - you will need to push your changes there and pull them on the remote host.
  3. It is not possible to push to branches that are checked out by default, thus you will not be able to deploy changes within the same branch using this approach
  4. It is harder to setup - you need to clone a repo on the remote host, so you need to actually get there via SSH first.

I believe there are many more drawbacks than advantages.

 

0
Avatar
Permanently deleted user

Ok, I see. I think the option or plugin to replicate those git commands that modify local repo state on the remote server still has value, but for now "Upload external changes" option is good enough for me.

By the way, what do you think about having PyCharm edit remote files directly? Currently to do this I have to mount remote file system locally using Win-SSHFS, which is extremely unstable, even when plain ssh works fine. Is there a way to do this without mounting the remote repo locally? Something like remote-atom: https://atom.io/packages/remote-atom but better integrated into IDE.

I'm working on two research projects (separate codebases, running simulations on up to 5 remote servers), and I do development on a windows laptop. If win-sshfs worked well, I'd just keep 5 mounted folders for those servers, and would be happy. But it doesn't, that's why I have to deal with the remote interpreters, and having to sync all my local changes with all those 5 servers.

0
Avatar
Permanently deleted user

Perhaps, but I'm not talking about right-click menu for a local file. I don't see the need to keep a local copy. Basically what I want is the same functionality as when I'm opening ssh connection to remote host, then editing a file there with vim, only done through PyCharm IDE. So that when I click on the file in the project tree structure in the left panel, it opens the remote file for editing, not the local copy.

0
Avatar
Permanently deleted user

Oh wait, this has already been implemented: https://blog.jetbrains.com/pycharm/2015/06/feature-spotlight-editing-remote-files! Why didn't you tell me? :)

 

0

You cant do this within PHPStorm but you can from an external script.  Just set up an 'External Tool" to run this script


#!/bin/bash

branch=$(git symbolic-ref --short HEAD)

ssh myName@remote-server cd /var/www/sugarcrm;git checkout $branch;git pull

0

I also suffered this issue recently.
I believe the issue lies in certain files within the .idea folder, which I ignored the entire folder when git push.

Description of my issue: 

After git checkout, the files on the remote deployment server were not updated.

My solution: (PyCharm 2022.3.1)

Right-click on the project
Deployment - Sync with Deployed to …

now you can see the different between local and server and upload every files from local to server.

I think it's not the best solution, but it work for me.

 

0

请先登录再写评论。