Setting up git for Drupal

Events happening in the community are now at Drupal community events on www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

Instructions for Windows

Note where I show a $ what follows is what you should type after the BASH $ command prompt.

I would recommend taking a look at this great set of video tutorials about git: http://learn.github.com/p/intro.html

Installing required programs

Download and install git for Windows from http://git-scm.com/downloads

Signup for github.com to store your git repositories conveniently online at https://github.com/ (Micro service is $7/month at time of writing, 22/9/12)

Download and install github for Windows from http://windows.github.com/

Sign into the github application with your github.com account, log in is at the top right of the application window

Create a new repository in the github application and make the first commits that the github application prompts you to make: .gitattributes and .gitignore

Configuring git

Make sure that git is installed on your server. I did this by installing the git web application in the Webfaction (my host) control panel.

Open the gitbash program – this will give you the $ command line

Add your name - $ git config --global user.name “Your Name”

Add your e-mail - $ git config --global user.email “your.email@example.com”

See the details that you have entered - $ cat ~/.gitconfig

Connecting to git on a remote server

Download and install and run PuTTY SSH client, to setup git on your remote server - type in the server you want to access in Host Name - eg. your_username@your_domain_name.com, then click Open, an SSH session will be opened and you will be prompted for a password (this will be specific to SSH and probably needs to be setup through your host’s control panel)

In your SSH session on PuTTY - $ git help git

This opens the git help documentation, press q to exit the documentation. This is to check git is working on your remote server.

Navigate to your git repository folder using the change directory (cd) command at the command prompt - $ cd $HOME/webapps/git/repos

Initializing git

Now create a new repository in your repos folder - $ git init

This should tell you that git initiated an empty repository

Ask the server to list files (ls) in the current (repos) directory showing detailed information and hidden files - $ ls -la

You will see that git has created a new directory called .git
Enter the .git directory - $ cd .git

Take a look at the files here - $ ls -la

Go back to the repos directory - $ cd ..

To see the path of the current directory with the print working directory command (pwd) - $ pwd

Adding changes to the staging area

Get git to recursively add files to the repository with add dot - $ git add .

See what git has added to the repository - $ git status

Tell git your name - $ git config --global your.name “Your Name”

Tell git your e-mail address - $ git config --global your.email “Your.Email@example.com”

Making a first commit

Create your first commit, use -m to add a message - $ git commit -m ‘Initial commit’

Git will tell you the files that have been commited

Now if you ask git’s status - $ git status

Git should tell you that there is nothing to commit in the current directory

Ask git what commits have been made - $ git log

To see all the branches you have in git - $ git branch

Can press tab when typing at command prompt to autocomplete

Setting up git for your Drupal install

Now go to the root of your Drupal installation - $ cd $HOME/webapps/drup

Create a git repository here - $ git init

Create a .gitignore file to prevent sensitive information and files that git will struggle with being added to the git repository - $ cat > .gitignore

Now type in the files and folders you want to ignore -

# Ignore configuration files that may contain sensitive information.
sites/*/settings*.php

# Ignore paths that contain user-generated content.
sites/*/files
sites/*/private

Press Control + D once you are done to save the file.

Add all changed files to git’s staging area - $ git add .

Commit all the changes in the staging area to the repository with a message - $ git commit -m ‘First Commit - Drupal Install’

Take a look at the list of all commits in your repository - $ git status

Pushing to a remote repository (on github)

Now tell git to connect to your remote repository on github (user and repository name are case sensitive) - $ git remote add github https://github.com/your_user_name/your_repository_name.git

Verify that your remote repository has been added - $ git remote -v

Now push all your commits to github with push [remote-name] [branch-name] - $ git push github master

You will be prompted to enter your github username and then your github password.

You should see all the files being sent to github.

Exit your SSH session on PuTTY - $ logoff

Adding Drush on the remote server

Connect to the server via SSH and enter the following commands:

cd ~

wget http://ftp.drupal.org/files/projects/drush-7.x-5.0.tar.gz

tar zxvf drush-7.x-5.0.tar.gz

ln -s ~/drush/drush ~/bin/drush

rm drush-7.x-5.0.tar.gz

which drush

Importing from a remote git repository to Acquia Dev Desktop

Open GIT Bash

Navigate to the Sites directory - $ cd Sites

Create a new directory for your site - $ mkdir SiteName

Navigate to the directory you created - $ cd SiteName

Use a Git clone command to download the site setup - $ git clone https://github.com/your_user_name/your_repository_name.git

You may want to move directories around - $ mv ~/Sites/SiteName/RepositoryName/* ~/Sites/SiteName

Make sure that .git, .gitignore and .htaccess transferred across

Use the backup and migrate module to migrate and save of copy of your site database to a directory on your local computer

Start Acquia Dev Desktop Control Panel

Select the drop down menu below Go To Site and select more

Click Import

On the new window, In Site Path, navigate to the Sites/SiteName directory

Under Database, select Create a new database and name the database SiteName

Change the name under Server to SiteName

Note: You may get an error message, “Error:hosts file doesn't exist or is not writable. 'C:\Users\Administrator\Windows\system32\drivers\etc\hosts'. If this is the case, find the C:\windows\system32\drivers\etc\hosts file, right click, select properties, un-check Read only, create your new site in the Acquia Dev Desktop Control Panel . Then if you are successful in creating the site go back to the hosts file properties and check read only. If this doesn’t fix the error, try disabling your anti-virus software temporarily.

Now run install.php by going to sitename:8082/install.php

Create new users for your site, preferably with the same details as your main admin accounts

Login as an Administrator, go to Modules and enable the Backup and Migrate Module

Go to Configuration > Backup and Migrate > Restore - navigate to the .mysql.gz file that Backup and Migrate created from your remote site earlier

You may want to upload some files like Site Logo and favicon.ico on the Appearance > CurrentSiteTheme > Settings page

Getting Drush working in git BASH

Install Drush for Windows from http://drush.ws/drush_windows_installer (when installing, be sure to select the option “Register environmental variables”)

Copy the following path: C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\ProgramData\Drush\;C:\Program Files (x86)\Drush\GnuWin32\bin;C:\Program Files (x86)\Drush\Php

In Windows, select Start>Computer>Properties>Advanced system settings>Environment Variables>New, for Variable name type “C:\path” and for Variable value paste the path you just copied

Open git bash

Test Drush is working $ drush status

Comments

Looks like some very useful

joachim's picture

Looks like some very useful information, but might it be better off (and more visible to more people) in the main git handbook on drupal.org?

Drupal Scotland

Group categories

Regions

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: