Getting started with Git (for Drupal) on Windows
This is a step-by-step guide to getting GIT working in Windows.
Note that what follows a $ is what you should type after the BASH $ command prompt.
I recommend taking a look at this great set of video tutorials about git.
Download and install git for Windows here.
Signup for github.com to store your git repositories conveniently online. (Micro service is $7/month at time of writing, 22/9/12) Alternately, bitbucket.org provides free private git repositories for up to five users.
Sign into the github application with your github.com account 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: .gitattributes and .gitignore.
Configuring git on your local server
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
Hands-on: Hook up with an GIT repository
For git you need the "GIT backend" module.
Here is an example of using GIT backend:
Step 1: create an bare GIT repository (skip this if you already have one)
mkdir bare.git
cd bare.git
git init --bareStep 2: set up your Drupal site with that repository
- Enable the "Version Control API", "Commit Log" and "GIT backend" modules.
- Flush cache.
- Go to Configuration > Development > Version Control settings (url: /admin/config/development/versioncontrol-settings)
- Set "Git binary path". (Notice: Can be problems with Windows OS. On *nix OS there are no problems with path)
- Go to Content > VCS repositories > Add Git repository in the admin area. (url: /admin/content/versioncontrol-repositories/add-git)
- Repository name: "Test repo", or whatever.
- Repository root: "/path/to/repository/bare.git".
- For other settings follow fields descriptions(and check "Web viewer URL handler" because by default it's not set. Might it'll be fixed in closest time)
- Save the repository.
- Enable the "Commit messages" menu entry, or go directly to the "/commitlog" path.
How to work on a patch that is not yet in core, but is needed as base cleanly
For twig we had the problem that the basic patch was not accepted, but that the followup issues should be clean.
The idea is to use two patches within one.
What do you do if you happen to find a patch with two patches in one?
Patch contributors
For patch contributors the workflow is not that difficult to the regular patches:
Assuming origin is the "core" repository and you work in feature branches the workflow is:
Lets further assume the patch is in issue 1806546 with comment number 4
Getting a clean branch:
# update core
git fetch origin
# checkout 8.x branch
git checkout origin/8.x
# checking out an issue feature branch with comment number
git checkout -b core-1806546-4Applying the current patch:
wget .../patch.diff
# this directly _commits_ the patches, conflicts are resolved like
# with rebase / merge
git am patch.diff
# Now you fork again with your new comment number
git checkout -b core-1806546-5Now you add your changes and then you do:
# this updates the original patch and can be done as often as you want
git commit --amend .
# this creates the new 2-part patch
git format-patch -M --stdout origin/8.x > mynewpatch.diff
# this creates the interdiff
git format-patch -M --stdout core-1806546-4 > interdiff.txtLinkified Git log messages for drupalcode.org and Issue queues.
A small shell function which linkifies git log output.
Modified from Ben Almans github version
- drupalcode.org commit link
- drupalcode.org blob links
- drupal.org issue link if the commit message is formatted as Issue #123456

# Git log with per-commit clickable Drupalcode URLs.
# @see https://github.com/cowboy/dotfiles/commit/78fde838a
function gdl() {
local remote="$(git remote -v | awk '/^origin.*\(push\)$/ {print $2}')"
[[ "$remote" ]] || return
local repo="${remote##*/}"
git log $* --name-status --color | awk "$(cat <<AWK
/^.*commit [0-9a-f]+/ { sha=substr(\$2,1,7); printf "%s\thttp://drupalcode.org/project/$repo/commit/%s\033[0m\n", \$1, sha; next }
/^.*Issue #[0-9]+/ { print; issue=substr(\$2,2); printf "\thttps://drupal.org/node/%s\n", issue; next }
/^[MA]\t/ { printf "%s\thttp://drupalcode.org/project/$repo/blob/%s:/%s\n", \$1, sha, \$2; next }
/.*/ {print \$0}
AWK
)" | less -R
}Note! This has only been tested on Ubuntu. I have a slight feeling less -R might not exist on osx.
TortoiseGit Usage
This page explains how you can use TortoiseGit under Microsoft Windows to contribute code to Drupal.org.
Other pages in this handbook explain how to install and configure TortoiseGit, and the differences between git and tradional versioning systems like SVN.
Requirements:
- You have requested and received git access.
- You have created a project.
- You have registered your public key with your drupal.org account.
- You have installed and configured TortoiseGit.
Now:
1. Create an empty directory where the repository of your project should live. (If you already have files for your project, you can add them here later.)
2. Right click the repository directory you have just created and choose "Git Create repository here..." as shown below:
TortoiseGit should reply by saying that an empty repository has been created. The result is that you now have a directory that functions as a local git repository.
3. Create your project files in the repository directory or copy existing project files there.
4. Once you have at least one file in the repository directory, commit it. You do this as follows.
- Right click the file(s).
Advanced Git configuration
Aliases
git aliases are a powerful way to streamline your most frequent git operations. Read a basic tutorial here. Git Immersion also has a section for aliases.
-
git diffup: Create full patch, interdiff.txt, and commit log in one shot for sandbox patches.
Applies to:
- Larger or more complex core patches, which are developed and improved in a sandbox branch.
Assumptions:
- You won't push commits upstream before you create a patch for a d.o issue.
- You want to combine and enforce best practices:
- Obviously, providing interdiffs for others.
- Doing atomic and clean commits.
- Writing proper commit messages.
(The shortlog can be copied 1:1 into an issue comment.)
- Your local branch
footracks the upstreammysandbox/foobranch.To configure/enforce this for existing branches:
git branch --set-upstream foo mysandbox/foo
Alias:
git config --global alias.diffup '!git log --oneline --reverse @{u}... && git diff 8.x... > $1 && git diff @{u} > interdiff.txt && echo'Explanation: