I just updated Drupal to 7.39 using Drush, in particular the command drush up and all related steps as explained here: https://www.drupal.org/node/2550801. During the update I have noticed this extremely worrying line, saying that Drush is messing with my .git directory: Drush tries to access the .git directory

and indeed after the update: enter image description here

So I got back the .git folder from the backup created by the Drush updater, committed and pushed.

The problem is that Drush, without any warning, not only corrupted the .git directory but also messed with my .gitignore file, deleting several lines.

As a result I pushed a very large number of cache and temporary files to my company's git repo and had to later fix it and apologise to my colleagues.

My question is: is there a way to update Drupal programmatically (no admin or manually moving files) without Drush trying to destroy my git repo?

  • 1
    The .gitignore file was changed by Drupal. Drupal ships with a .gitignore so when you update it overwrites the .gitignotre. I always just checkout my ignore file to revert to my custom one. What version of Drush are you using?
    – Brady
    Aug 25 '15 at 10:09
  • 1
    As to the messing with git files. That has never happened to me in 3.5 years of Drupal work. Very odd...
    – Brady
    Aug 25 '15 at 10:11
  • 1
    That is the reason why you need to use diff and patch to avoid this kind of problem. Haven't used drush updb in all of my projects.
    – Gulok
    Aug 25 '15 at 10:18
  • Hi Brady yes it's very odd regarding the .git, even I was very surprised, I'm thinking to file a bug but I'm not sure if the bug is related to Drush or to the Drupal core update itself. Regarding the .gitignore, I understand the reasoning behind it but I think that at least the update procedure should warn you! As you do, I also commit my .gitignore so I was able to retrieve it easily but in the meantime all my colleagues were already asking my why I had pushed files that weren't supposed to be pushed LOL... I think 99% of people will add new lines to the default gitignore :-)
    – mastazi
    Aug 25 '15 at 10:20
  • 1
    You should probably file an issue on the drush github queue (I don't see one there, yet): github.com/drush-ops/drush Aug 25 '15 at 17:08

The deletion of the .git directory and other non-Drupal files when running drush up drupal has been a somewhat randomly occurring problem for many Drush users as documented on this GitHub issue. As far as I know, no definitive reason for this behavior has been found, and there is even debate about whether this behavior is, or should be, by design.

In my experience and that of others participating in the GitHub discussion, this deletion of the .git directory did not happen when using Drush 6, but happens in some circumstances when using Drush 7 or 8. Therefore, there's no surefire way of avoiding the deletion of the .git directory and other non-Drupal files when running drush up drupal besides moving those files out of the Drupal root directory before running the update.

However, the overwriting of .gitignore when running drush up drupal occurs by design. .gitignore is a core Drupal file, and as Drush warns, updating core will discard any customizations:

Code updates will be made to drupal core.
WARNING:  Updating core will discard any modifications made to Drupal
core files, most noteworthy among these are .htaccess and robots.txt.  If 
you have made any modifications to these files, please back them up 
before updating so that you can re-create your modifications in the 
updated version of the file.

.gitignore isn't mentioned explicitly in that warning, but it is treated similarly since it, too, is a Drupal core file.


Try this, I'm searching for this topic and I found a solution.

At first you need to move .git, .gitignore... folder out (You need to be at web root)

mv .gi* ../

After that you can run drush up normally without affect any git files

drush up drupal -y

Finally you need to move .git, .gitignore... folder back and then apply your commits like such file changes

mv ../.gi* ./

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.