Given you have the following workflow:
- A local PC or Mac with PhpStorm
- A remote server where all your staging/production files are stored
Your aim is to edit selected local files on the remote server but not take a hold of the entire project as it’s too large and will take long and / or take up a lot of disk space.
You wish to edit the files locally on your PC or Mac, then publish to Github so that you have version control, and then pull the remote changes onto the server so that the server is up to date.
You’re starting from fresh.
Create a blank project on Github without the readme.
On the remote server, in the root directory of the project:
‘git add’ the files you want to be added, e.g.
git add modules/addons/zomex_template_manager/lang/english.php
git commit -m "First commit"
Add your credentials:
git config --global user.email "[email protected]" git config --global user.name "Your name"
Add the remote:
git remote add origin https://github.com/yourrepo/yourproject.git git push origin master
Now in PhpStorm start a new project from Existing Files, and specify your Github credentials. You will be presented with your Github projects. Choose the correct project.
Make changes to the file. Use Control K to publish to Github, and then Push in PhpStorm.
Back on the remote server:
git fetch && git pull
Git pull will fail. Do this:
git branch --set-upstream-to=origin/master master
Now to `git pull` again.
You now have a round trip workflow. Henceforth you only have to publish and push from Github, and fetch and pull on the remote server.
If you’re having to type your credentials the whole time, do this:
git config credential.helper store
Some errors you might encounter:
git pull fatal: refusing to merge unrelated histories
You could try this but be sure careful as it resets the merge history:
git rebase origin/master
The key is the comment provided on the Stack Overflow post:
“This branch tracking is set up for you automatically when you clone a repository (for the default branch only), but if you add a remote to an existing repository you have to set up the tracking yourself. Thankfully, the advice given by git makes that pretty easy to remember how to do.”