User login


Maintaining a Drupal project with Git: Vacating the master branch

If you've already been committing code to master, do this to start a new 7.x branch and kill off the code in the master branch so noone gets confused.

cd /path/to/repo
git checkout -b 7.x-1.x

git push origin 7.x-1.x

git checkout master
git rm -r *
echo "Real code is not kept on the master branch, to see the code: git checkout 7.x-1.x" > README.txt
git add README.txt
git commit -m "Add a README explaining that the master branch is empty."
git push origin master

Set a git commit message in bash but also go to Vim for further editing

A colleague insists that messages abide by the 72 character limit advisory, and i want to change my habit to get the files-changed and, just as important, files-left-out information that git commit will give in the Vim editor.

I'm still a bit addicted to the git commit -m "Message here" workflow of entering messages right in the command line, and it's more than just habit: it is very useful to be able to look at the git add -p record.

Git rebase workflow and git ahead and behind messages

Update: Just set it up to be automatic.

For all new projects:

git config --global branch.autosetuprebase always

For existing projects:

git config branch.master.rebase true

Courtesy Randy Fay's blog post, "Simpler Rebasing (avoiding unintentional merge commits)"

git pull --rebase
rebasing applies your changes on top of the fetched commits.

Remember to add and commit before pushing a new

Just created a new sandbox project, and try to push it to d.o:
git push origin master

error: src refspec master does not match any.

When you are putting a new project on means you haven't committed anything yet!

git init is not enough, heh.

(Yes, i googled this before figuring thisout, so if that's how you got here, you are not alone)

Enhance your prompt with git information

Git provides a series of enhancements for the bash prompt. It can display the current branch when inside a working copy. Here's an example from my machine:
{syntaxhighlighter brush: bash; gutter: false}
stefan@debian:~/Documents/Projects/Drupal/test(master *)$
It shows the branch name and indicates by an asterisk that I have uncommitted changes.

Installing Drubuntu

This is for Ubuntu 10.10 with the intention of doing primarily Drupal 7 development.

Get the link to the current version of Drubuntu from the Drubuntu project page, and use it thusly:

tar -xzf drubuntu-7.x-10.10-beta1.tar.gz

Understanding past changes with diff and git log

In figuring out what changed in a theme's files (an incorrectly made subtheme; instead of overriding the base themes stylesheets, changes should have gone into its own files with different names), these commands were useful.

diff -uP themes/bartik/css/colors.css sites/default/themes/dgd7theme/css/style.css > theme.diff
git log --cc sites/default/themes/dgd7theme/css/style.css > log.diff

Kept running them for the three different files, and reloading theme.diff and log.diff in gvim to see the changes. Quite convenient.

Git undo part of a commit

To revert an entire commit.

git checkout <file>
re-checkout <file>, overwriting any local changes

Should be able to git add changed files that you are interested in committing the revised changes and git commit --amend

Syndicate content