Drupal development using Git, Sublime Text and Console under Windows
This guide is compiled for Drupal Estonia Hackday where I held a workshop on Drupal development under Windows. For a long-time OSX user it struck me that creating a fully working development environment under Windows is not that hard at all.
Note that this guide only deals with command line and code editing experience, it does not help to set up LAMP stack for Drupal.
Getting started
- Install Git http://git-scm.com/download/win
- Install Sublime Text http://www.sublimetext.com/2
- Install Console http://sourceforge.net/…est/download. Note that you will need to unpack, copy "Console2" dir to to "C:\Program Files (x86)" and create shortcut icon yourself.
- Install Drush http://drush.ws/…ws_installer
What about Github for Windows?
Freshly baked http://windows.github.com eases some of the pain of setting up Git on Windows and also includes full Git command line client but it's best for developing for Github only. Non-Github remote repositories are supported, but they are a bit buggy, at least in initial version. At the time of writing only cloning works nicely, building local repo and assigning remote is not properly recognized and need extra steps. Also, re-using Github SSH keys requires command line knowledge and autogenerated dotfiles (.gitignore etc) might bring confusion for newcomers. Still this pretty Github application might bring a lot of potential in the future, especially for visual merging etc.
Setting command line alias for Sublime Text
- Run "Git Bash"
- Enter following commands:
echo 'alias sub="/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.profilesource ~/.profile
Now you can enter sub .
in any directory in the command line to run Sublime Text.
Also, you might want to configure Sublime Text to more predictable startup experience. Go to Preferences -> Settings – User and adjust following settings to false:
"hot_exit": false"remember_open_files": false
Setting Git default editor to Sublime Text
To save you from thrown into Vim when commiting without -m option it's wise to set Git to throw you to Sublime Text instead.
git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"
Set up Console to run Git shell
- Run Console
- Go to "Edit -> Settings"
- Fill "Shell" field with
C:\Windows\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login -i"
4. Fill "Startup dir" field with your working directory, usually something like C:\Users\your_username\your_working_directory
See also http://lostechies.com/…into-console
Set up Git config
git config --global user.name "my fullname goes here"git config --global user.email my_email_goes_here
Note that you must fill in my fullname goes here
and my_email_goes_here
. E-mail must match with e-mail you have used for registration in Drupal.org.
There are many additional tricks to set up a more workable Git config, for examples see here: http://coderwall.com/p/euwpig?…
Generate SSH Keys
First, make sure you have Drupal.org account http://drupal.org/user/register and you have applied for Git access in Drupal http://drupal.org/node/1047190. You also might want to have Github account https://github.com/signup/free
ssh-keygen -t rsa -C "my_email_goes_here"sub ~/.ssh/id_rsa.pub
Note that you must to fill in my_email_goes_here
. Actually, it does not have to be e-mail, it can be any string but using e-mail is a convention.
Upload SSH keys
Then copy all the contents of the ~/.ssh/id_rsa.pub
file to:
…to Drupal.org:
http://drupal.org/user ->Version control -> Profile -> SSH Keys (help here).
…to Github:
https://github.com/settings/ssh (help here).
Finally, lets started with Git
Creating new repo
mkdir testcd testgit initecho "About this project" > README.txtgit add .git commit -m "Initial commit"
Push repo to Drupal
First create a new sandbox project in http://drupal.org/…ject-project. When done, navigate to Version control tab and run
git remote add origin your_drupalname@git.drupal.org:sandbox/your_drupalname/your_sandbox_id.gitgit push origin master
Note that you must to fill in your_drupalname
and your_sandbox_id
.
…or push repo to Github
Go to https://github.com/new, ignore "Initialize this repository with a README" setting.
git remote add origin git@github.com:your_username/your_projectname.gitgit push origin master
Note that you must to fill in your_username
and your_projectname
.
Git and Drupal development
Apply a patch with three lines
git clone <a href="http://git.drupal.org/project/drupal.git" title="http://git.drupal.org/project/drupal.git">http://git.drupal.org/project/drupal.git</a>cd drupalcurl link_to_the_patch | git apply
Note that you must to fill in link_to_the_patch
with actual URL
Roll back in one line:
git reset --hard
Create a patch for Drupal:
There is comprehensive manual for creating Drupal patches http://drupal.org/…instructions but in most simple form it goes like this:
git clone <a href="http://git.drupal.org/project/drupal.git" title="http://git.drupal.org/project/drupal.git">http://git.drupal.org/project/drupal.git</a>cd drupalsub ....edit something and save...git diff
This gives you a overview what you have changed. To save patch to a file, run:
git diff > ~/my_patches_dir/my_patch_name.patch
More info about Git