How to prevent git pull from overwriting a file? - wordpress

I use Git and GitHub to push changes I make on my local web development environment to my GitHub account and from there I pull these updates to my live production site. I am working with WordPress, so what I have done is .gitignore the wp-config.php file as my productions site has its own unique wp-config.php file with its own respective database credentials. As I am git ignoring this file, when I pull to my production site it gives me the following error:
error: Your local changes to the following files would be overwritten by merge:
wp-config.php
Please, commit your changes or stash them before you can merge.
Aborting
How do I prevent this wp-config.php file from being overwritten (more specifically deleted) when I do a git pull?

This is your machine specific config file. For such case its better to use build tool. For you its better to create your custom configuration on a special file my-config.php and include it in wp-config.php. Also ignore my-config.php in .gitignore. Now you'll never see any problem like this.
What you will see is my-config.php file not found error. And write it about in your README.
I do this whole thing with configure, make even the project is in php
If this was not a config file, and you are sure about the changes you can commit first and then execute pull. Other option is stash which is already told in the error message.

Your changes won't be overwritten. That's what the error message is telling you. The pull failed because git doesn't want to overwrite your changes.
To allow the pull to take place and keep your changes, do git stash before pulling. This will save a copy of your changes and allow you to pull without any issue. Then git stash pop after pulling will restore your changes. Note that you may experience a merge conflict if the changes you are pulling to wp-config.php touch the same part of the file as your local changes.

The other side doesn't have the ignore file in effect yet. Once it's there, you won't have this message. Also it's still tracked. So in addition to changing the .ignore file on both sides, you also need to delete it on both sides and from then on it will not get in the way.
Also take a look at octopress if you are going to be using git as part of your blogging routine.

Related

Git: Ignored a file, now says there's unmerged files and can't pull

Previously, I had WordPress' wp-config.php committed; since then, I've now ignored this file in .gitignore, which is fine.
Unfortunately - now when pulling to live, it provides this error:
M .htaccess
U wp-config.php
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
Before this issue happened, I had an issue with pulling where it said I had uncommitted changes with these files - so I let it overwrite them, then I uploaded the actual files manually via FTP, which caused this new error.
I want to keep the files in their current state on the live server, but get around this error now and in the future.
What is the process of being able to pull the latest changes with this?
UPDATE - I'm adding an answer to a question posed in comments, and clarifying a related point
First let's clear up a little confusion: This error has nothing to do with putting the file in .gitignore. In fact, since the file is present in the index, .gitignore has no effect whatsoever on the file.
Before this issue happened, I had an issue with pulling where it said I had uncommitted changes with these files - so I let it overwrite them
You may need to be more clear about what commands you issued and what output you saw, because this is where your trouble is coming from.
When you say you "let it overwrite them", what does that mean? git resists overwriting local changes (especially uncommitted changes)...
I'm guessing what really happened is that git tried to merge changes from the remote repo into your local changes for those files, but had merge conflicts on wp-config.php.
And most likely it's still in a merging state, which you'll have to resolve before you can move on. If you say git status it will likely tell you that you're merging, with some changes "to be committed" (likely including the .htaccess file) and some "unmerged paths" (likely including the .php file).
If you have the .php file looking the way you want it in the work tree, then you can say git add wp-config.php and then git commit which should cause the merge to complete. (More generally, you have to get the file looking how you want it in the index, and do this in a way that tells git the conflict is resolved; and then you can commit to get out of the merging state.)
Now in comments you ask about whether this will put the file "back" into git. And that comes down to what it means to "have the .php file looking the way you want it".
If you never want git to provide the .php file (even during a fresh clone), then you need to remove it from the index and subsequent commit.
You could (at least temporarily) remove the file from the working tree and then do a git add (as noted above). Or, if you don't want to affect your working tree version, you can
git rm --cached wp-config.php
directly making the index look "how you want it". At this point it becomes possible for your .gitignore entry to help you avoid accidentally reintroducing the file.
If what you mean is that the file should be there, but only a default version should be in the repo (not taking any changes that might be made in the working tree), git won't do that. You'll have to get where you're going a different way. For example you could put the file in the repo as wp-config.php.default and ignore the wp-config.php path. After cloning the repo you would then copy the default file, and any local changes would be made only to the ignored copy.

Remove file from Git without deleting them locally and remotely

I have a repository for a Wordpress intall that currently has all the Wordpress files included.
I have updated my .gitignore to only include the theme folder but when I push to my staging server it deletes all the files.
I need to keep all the files both locally and on the server, but I want them to stop being tracked and removed from the repository, Ideally with the history still intact.
Thanks in Advance
The server has a copy of the repository, so if you remove anything from the repository it will be removed from the server's repository as well (after you push).
However, you can set git to assume the files are unchanged. This will keep them in the repository, but git will stop detecting new changes to them.

Git: How do I pull to a server without bringing the metadata?

I have a staging server I'd like to set up to git pull whenever updates are made to a BitBucket repo. It would be a single repo with multiple submodules, but I can break it apart if that's better.
It'd be a theme that goes to wp-content/themes/
And single/multiple plugins that go to wpp-content/plugins
My question is, (1) is this good practice? and (2) how can I pull the changes without introducing the .git metadata to those (or any public) directory? I assume the metadata has to be somewhere, but how can I hide it?
If this is too vague, please feel free to ask for clarification on something.
Thanks!
Just put the whole thing under git ?
Use .htaccess to disallow the .git folder.
You can use multiple repositories but updating means going to each one and git pull / git fetch git merge.
you could also move the .git directory outside of the web root, make a file called .git with the contents
`gitdir: /path/to/.git`

CVS Update - move away file

I am updating files in CVS. I put files that I needed to update in my unix folder.
Using cvs add, cvs commit - I was able to add new files to directory.
I was also able to update some from 1.1 to 1.2 using cvs update.
However I am unable to update the version for one file, getting this error:
cvs update filename.scr
cvs server: move away filename.scr; it is in the way
Any ideas how to solve this?
Do exactly what it says - remove filename.scr. CVS update won't overwrite the existing non-controlled copy of filename.scr.
in the cvs hidden sub folder check if the folder of that file is on the list of entries, if so you have to add it
To be specific, this means there's a file in the repository, and a matching file in your tree, but the file CVS/Entries doesn't mention it. That can fail either for the CVS/Entries file at the same level as the file it's complaining about, or if you do a recursive update, it can fail due to the directory not being listed in CVS/Entries at a higher level.
This happens often to me, and I don't know why; a perfectly good checkout starts to get these errors. If it is a missing directory, the easiest fix is to directly edit CVS/Entries, e.g. to add
D/Foo////
to Bar/CVS/Entries so that CVS knows it already owns Bar/Foo.
If it's missing a file, it's hard to regenerate the CVS/Entries line, so it's easiest to do as it says and delete the file.

How do I configure git to create files with the right permissions?

I have a git repo that includes submodules for wordpress and a wordpress theme. I am trying to configure this so that I can run "git pull" on the server whenever there is a change, to update the files from the repo. The problem I am having is that after I do a git pull, I end up with a 500 error on the front end and my server logs saying "file is writeable by group". Basically, I need all of the files to have the permissions of "0755" and to stay that way after I update them with git. How can I set this up correctly?
Check out the documentation on filemode. In your repository under .git/, the config file has a section starting with [core]. If you set filemode to FALSE (or zero, I can't quite recall), it will stop git from changing permissions on any of the files. Then, you can just update them to the right permission and leave them alone.
Note that you could run into other permissions errors if you are having git run as a separate user (we do this with a git user who runs automated updates). Just something to be aware of as you set things up.

Resources