home / tools / git
# Git

## Hooks

The [Lithium QA Project](http://rad-dev.org/lithium_qa) hosts a collection of git hooks & scripts that can be useful in the development process of a Lithium application. 

There also exists a [regex based pre-commit hook](http://trac.assembla.com/mi/browser/misc/hooks/pre-commit-standalone), which is superceeded by (but obviously has dependencies) a [shell pre-commit hook](http://github.com/AD7six/cake_autotest/blob/master/vendors/pre-commit) by AD7six.

## Rebase Considered Harmful

As described in [this blog post](http://changelog.complete.org/archives/586-rebase-considered-harmful) you should only rebase if you are working on a private (local) branch. 

Citing the man page for `git-rebase`:

"Rebasing (or any other form of rewriting) a branch that others have based work on is a bad idea: anyone downstream of it is forced to manually fix their history. This section explains how to do thefix from the downstream's point of view. The real fix, however, would be to avoid rebasing the upstream in the first place."

The man page also has a chapter title _RECOVERING FROM UPSTREAM REBASE_.

## Merging

While in general rebasing is not recommended, there is one case where `git rebase` seems to work well. The case starts with some changes in a fork. For the sake of the example we'll call this `archer`. Archer has some changes in his `docs` branch. We want to grab the changes and merge them back into the main branch, called 0.3. To do this we will create a local copy of archer's branch, then rebase it, review the changes, fix the conflicts, merge it, and remove the rebased copy of archer's branch

- add archer's remote
 * `git remote add archer code@rad-dev.org:forks/Archer/lithium.git`
- grab archer's tree and switch to a local branch based on docs
 * `git fetch archer`
 * `git checkout -b archer.docs archer/docs`
- then interactively rebase it on 0.3
 * `git rebase -i 0.3`
- go back to the 0.3 branch and merge the rebased copy
 * `git checkout 0.3`
 * `git merge --no-commit archer.docs`
- review the merge and commit
 * `git commit -m "merging archer's docs branch"`
- now delete the rebased branch
 * `git branch -d archer.docs`


## Renaming Files

As of [this post to the frysk project mailinglist](http://sourceware.org/ml/frysk/2008-q1/msg00004.html) you should follow these steps when you're renaming a file in order to preserve it's history:

* rename the file `a.php -> b.php`
* `git add . && git add -u .`
* commit
* edit the contents of `b.php`
* `git add -u`
* commit

**Or** use ```git mv``` which does the same thing(?).