Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI'm at a point in my git education where I've refined my .gitignore file such that when I push from my local development machine to a remote repository (which happens to be on Azure, but it could just as easily be on github), the folders and files in the repo are precisely how I want them to be. That is:
- wp-content/plugins/my-custom-plugins
- wp-content/themes/my-custom-theme
...and that's basically it. I don't want the wp-config in the mix, or any of the stock WP folders like wp-includes or wp-admin. No cache, no wp-content/uploads, etc.
Enter my question: When I SSH into the Linux web server where my website is hosted, how do I perform a git pull origin dev
so that git doesn't delete my entire WordPress site, replacing it with only the folders/files in the repo?
What I've Tried:
First of all, when I perform git pull origin dev
, the operation does, indeed, wipe out all of my WordPress files and leave only the pulled repo. Unacceptable, to say the least.
Since this is the development server, I can afford to play around with it and get it wrong, because I can always FTP the website back to the server. FTP'ing is very time consuming, so I don't want to get this wrong too many times. And when it comes time to do it on the production server, I cannot get it wrong even once.
I am answering the question myself, because for some reason it is attracting other comments and answers that are unrelated to the original question. I guess you can have a high rep and still have low reading comprehension.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI'm at a point in my git education where I've refined my .gitignore file such that when I push from my local development machine to a remote repository (which happens to be on Azure, but it could just as easily be on github), the folders and files in the repo are precisely how I want them to be. That is:
- wp-content/plugins/my-custom-plugins
- wp-content/themes/my-custom-theme
...and that's basically it. I don't want the wp-config in the mix, or any of the stock WP folders like wp-includes or wp-admin. No cache, no wp-content/uploads, etc.
Enter my question: When I SSH into the Linux web server where my website is hosted, how do I perform a git pull origin dev
so that git doesn't delete my entire WordPress site, replacing it with only the folders/files in the repo?
What I've Tried:
First of all, when I perform git pull origin dev
, the operation does, indeed, wipe out all of my WordPress files and leave only the pulled repo. Unacceptable, to say the least.
Since this is the development server, I can afford to play around with it and get it wrong, because I can always FTP the website back to the server. FTP'ing is very time consuming, so I don't want to get this wrong too many times. And when it comes time to do it on the production server, I cannot get it wrong even once.
I am answering the question myself, because for some reason it is attracting other comments and answers that are unrelated to the original question. I guess you can have a high rep and still have low reading comprehension.
Share Improve this question edited Mar 2, 2021 at 16:51 TARKUS asked Mar 1, 2021 at 15:57 TARKUSTARKUS 13710 bronze badges 7 | Show 2 more comments2 Answers
Reset to default 1Enter my question: When I SSH into the Linux web server where my website is hosted, how do I perform a git pull origin dev so that git doesn't delete my entire WordPress site, replacing it with only the folders/files in the repo?
git pull origin dev
git pull
does not erase or replace untracked files.
Proof
For example, here is an example git repo with a README.md
: https://github/KalobTaulien/example-repo
Any repository will do however, so lets do the following:
- clone the repository into a folder
- create an untracked file in that folder
- run
git pull
If you are correct, the untracked file will be deleted.
This is the result:
~
❯ cd /tmp
/tmp
❯ git clone https://github/KalobTaulien/example-repo
Cloning into 'example-repo'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 18 (delta 1), reused 1 (delta 0), pack-reused 12
Receiving objects: 100% (18/18), done.
Resolving deltas: 100% (3/3), done.
/tmp
❯ cd example-repo/
/tmp/example-repo ᚴ:master
❯ touch test.txt
/tmp/example-repo ᚴ:master
❯ ls
README.md test.txt
/tmp/example-repo ᚴ:master
❯ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
/tmp/example-repo ᚴ:master
❯ git pull origin master
From https://github/KalobTaulien/example-repo
* branch master -> FETCH_HEAD
Already up to date.
/tmp/example-repo ᚴ:master
❯ ls
README.md test.txt
As you can see, test.txt
was not erased.
In Conclusion
How do you pull files down without erasing files and folders not tracked by git in the same folder? git pull
. git pull
does not erase files and folders not tracked by git
.
Your theory that git pull
is responsible is incorrect.
Why?
git pull
is shorthand for these commands:
git fetch
git merge FETCH_HEAD
Neither of those commands touch untracked files. fetch
retrieves information about the remote branch. merge
applies new commits to the current working directory.
As for why your WordPress files and folders are deleted, we don't have enough information to reproduce the problem or diagnose the cause. Being able to see the git repo itself, and all of the commands used, might help diagnose the problem.
For example, it may be that before pulling, your scripts do a hard reset and clean. Or that you aren't doing the git pull
at all, but rather a tool is doing it. It could also be possible that the git repository has script hooks that run on pull
that run additional commands that you have not told us about.
However this is not a WordPress problem, it's a git
question. You should ask about this on Stack Overflow.
A wordpress.stackexchange moderator closing a question after he answers it? Nobody else sees the self-serving conflict of interest? Hmmm...
Tom J. Nowell's comments and answer completely misstate the problem, and his revenge downvoting, then answering the question, and then CLOSING the question should be beneath the dignity of a moderator on this site. Such behavior does nothing to edify credibility. I suppose now I will be subject to retribution on any other question I post or respond to on this site.
The other answer posted by a user with a higher rep than mine, although long-winded, actually does not address my original question.
For a better answer than that given, refer to the answer marked as correct here: SSH git — How to pull a folder from repo, but not delete other directories & files on deployment server
So, in the interest of maintaining focus on the actual question asked, I will answer my own question. I don't think this is a perfect answer, and I invite better answers.
What I've Tried:
First of all, when I perform git pull origin dev
, the operation does, indeed, wipe out all of my WordPress files and leave only the pulled repo. Unacceptable, to say the least.
- Repo comprises the wp-content folder, and only the wp-content folder
- SSH into my remote web folder root.
- git pull origin dev
Result: My WordPress installation is wiped out, leaving only the wp-content folder with wp-content/plugins/{custom_plugins} and wp-content/themes/{active_theme}.
THAT is the problem.
The solution (really, my solution of the moment) is to create a temp folder in my webroot, and pull the repo into the temp folder, and then use a bash command like mv -u
(move only updated files) or cp
to move or copy the new repo files from the temp folder to the working folder. This preserves all the other WP folders and files.
Another answer:
- I created a folder called "test" on the web server.
- Using ssh and bash, I
cp -r
(copied) all WP from my remote's web folder to an empty "test" folder. - I wasn't allowed to do a pull from the repo until I did a
git pull origin dev --allow-unrelated-histories
Now, my web folder still has all my WP files and folders, with the custom plugins in wp-content/plugins and custom theme in wp-content/themes correctly overwritten by the repo files.
git pull
doesn't abort due to untracked files on my server, had you modified a tracked file on the server e.g. via automatic updates or manual changes? The ideal setup is that thegit
repo is your source of truth, and that all changes are done viagit
, with onlywp-config.php
being the exception. Keep in mind though this stack is for WordPress questions, if you have a generic git question that's better asked on stackoverflow where it will help more people – Tom J Nowell ♦ Commented Mar 1, 2021 at 16:34wp-content
then why would it pull other things? I think you need to explain your question clearly using fewer words, it's confusing. If your git repo is justwp-content
then clone it to thewp-content
folder, what do the other folders likewp-admin
have to do with it? Are you saying that your git repo has awp-content
subfolder? If so stop that, and move everything up one folder so that the git repo is yourwp-content
folder, not your WP install root – Tom J Nowell ♦ Commented Mar 1, 2021 at 18:34wp-admin
etc being deleted is not the behaviour ofgit pull
. I have lots of git checkouts that contain untracked files, and those files don't get deleted when Igit pull
. What you have are basic git questions, you should ask on stackoverflow. When you do, include output from the commands – Tom J Nowell ♦ Commented Mar 1, 2021 at 19:39git pull origin dev
will not wipe out untracked files, so you've got something else wrong that you're not telling us. AFAICS that would only delete files if 1) those files were tracked by git in the previous checked out state of the repo 2) you're on the dev branch already 3) you deleted the files in the remote copy. – Rup Commented Mar 2, 2021 at 14:37