For the record, here are the two solutions I am finally using based on the answer of Craig Otis here pointing at the answer of lindes on "Finding a branch point with Git", using Bash aliases the ".gitconfig" file (tested under Linux Ubuntu 12.10)
Initial state, where the branch "fix/123" has already been merged back into "master":
I--J (stable)
/
- A - B - C - D - E - F - G (master)
\ /
X - Y (fix/123)
1) To rebase the branch "fix/123" starting from "master" onto "stable" (this is a generic answer for most people reading this):
Add the following Bash aliases into your ".gitconfig" file:
[alias]
oldest-ancestor = !bash -c 'diff -u <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | sed -ne \"s/^ //p\" | head -1' -
rebase-onto = !bash -c 'git rebase --onto $1 `git oldest-ancestor $2 $3` $3' -
Then use the command line:
git rebase-onto stable master fix/123
And here you are:
I--J (stable)
/ \
/ X'- Y' (fix/123)
/
- A - B - C - D - E - F - G (master)
\ /
X - Y
2) To rebase the branch "fix/123" starting from "master", creating a new branch "fix/123-stable" onto "stable" (this is the more specific answer I am going to use).
Add the following Bash aliases into your ".gitconfig" file:
[alias]
oldest-ancestor = !bash -c 'diff -u <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | sed -ne \"s/^ //p\" | head -1' -
rebase-onto = !bash -c 'git branch $4 $2 && git rebase --onto $3 `git oldest-ancestor $1 $4` $4' -
Then use the command line:
git rebase-onto master fix/123 stable fix/123-stable
And here you are:
I--J (stable)
/ \
/ X'- Y' (fix/123-stable)
/
- A - B - C - D - E - F - G (master)
\ /
X - Y (fix/123)