{"id":439,"date":"2013-08-13T08:07:00","date_gmt":"2013-08-13T16:07:00","guid":{"rendered":"https:\/\/maxbronsema.com\/blog\/?p=439"},"modified":"2013-08-13T08:07:00","modified_gmt":"2013-08-13T16:07:00","slug":"how-to-use-git-to-update-drupal-when-you-cant-use-drush","status":"publish","type":"post","link":"https:\/\/maxbronsema.com\/blog\/2013\/08\/13\/how-to-use-git-to-update-drupal-when-you-cant-use-drush\/","title":{"rendered":"How-to: Use git to update Drupal when you can&#8217;t use Drush"},"content":{"rendered":"<h3>Problem:<\/h3>\n<p>You have code on a production server that does not allow Drush to be running and you do not enjoy the idea of copying over live files. If these sites are already tracking a git repository that is great, simply do a push and pull and you are done. It gets more complicated though if the repositories are woefully out of sync or if they have never had a git repository configured.<\/p>\n<h3>Proposed Solution:<\/h3>\n<p>The solution I devised allows you to update the site locally, make a nice commit, and then fetch it on the remote server and reset the filesystem to the fetch that was just made. Here are the steps:<\/p>\n<ol>\n<li>Create a git repository within your development site (skip this step if you already have git enabled).\n<pre>$git init<\/pre>\n<\/li>\n<li>Use Drush on your development site to update Drupal core.\n<pre>$drush pm-update drupal<\/pre>\n<\/li>\n<li>Test your site and then add and commit the files you have just updated.\n<pre>$git add -u\r\n$git commit -m\"Upgrade to Drupal version x.yz\"<\/pre>\n<\/li>\n<li>Create a remote repository if you do not have one already configured. Once that is created link your development repository to the remote and push your updates.\n<pre>$git remote add origin RemoteRepositoryURL\r\n$git push origin master<\/pre>\n<\/li>\n<li>Now, go over to your production site and create a git repository like in step 1 above. Next, you will add the remote, fetch the update from that remote, and then reset your file tree to what you just pulled with the<a href=\"http:\/\/stackoverflow.com\/questions\/1125968\/force-git-to-overwrite-local-files-on-pull\"> following commands<\/a>.\n<pre>$git init\r\n$git remote add origin RemoteRepositoryURL\r\n$git fetch --all\r\n$git reset --hard origin\/master<\/pre>\n<\/li>\n<li>That last command will rebuild the file system based on repository and from now on you can do normal push and pulls. Make sure to run update.php to get your database in sync with the new Drupal release.<\/li>\n<\/ol>\n<h3>Reflection:<\/h3>\n<p>I know the above is quite unorthodox. You also need to be careful as it will only rebuild the files you are tracking. I do not normally advocate for tracking entire Drupal installs but if you are in a situation as detailed above, it may be one of the few ways to have a sane update mechanism. For working with remotes I find the <a href=\"http:\/\/git-scm.com\/book\/en\/Git-Basics-Working-with-Remotes\">git-scm reference pages<\/a> very handy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: You have code on a production server that does not allow Drush to be running and you do not enjoy the idea of copying over live files. If these sites are already tracking a git repository that is great, simply do a push and pull and you are done. It gets more complicated though &hellip; <a href=\"https:\/\/maxbronsema.com\/blog\/2013\/08\/13\/how-to-use-git-to-update-drupal-when-you-cant-use-drush\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How-to: Use git to update Drupal when you can&#8217;t use Drush<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":440,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,39,50,2],"tags":[],"class_list":["post-439","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-drupal","category-git","category-linux","category-web-development"],"_links":{"self":[{"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/posts\/439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/comments?post=439"}],"version-history":[{"count":1,"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/posts\/439\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/posts\/439\/revisions\/441"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/media\/440"}],"wp:attachment":[{"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/media?parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/categories?post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maxbronsema.com\/blog\/wp-json\/wp\/v2\/tags?post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}