GitDeleteBranch

February 04, 2010
I'm learning a bit of git while in a subversion environment, mainly to do cheap dev branching. After successfully committing my first fix up from a git branch back into svn, I deleted the branch and didn't think much about it. Later I dcommit-ted a second fix on another local git branch and started to delete that branch but then got nervous. What could I do to ensure I wasn't about to delete something that had a pending change on it?

The PragProg Git book mentions that the default delete command provides a safety check and won't delete a branch that hasn't been merged. However, I realized that I hadn't merged my first bug fix branch back to my git master, so how was it that I was able to delete that branch? Had I found a loophole in the process since I was throwing some git-svn into the mix?

I found in the git-branch man a --merged option on the git branch command that should show me in advance what branches it considered safe to delete.

After playing around some, I realized I _had_ merged my original qc branch to my master branch, just not directly -- git (I presume) realized the merge had occurred because I'd done a git svn rebase command on master.

Here's a snippet from the console demonstrating this in action. Note, on the qc4042 branch I'd already done a git svn dcommit of all changes on that branch, but I hadn't dcommitted anything from the qc3937 branch.


c:\src>git branch
* master
qc3937
qc4042

c:\src>git branch --merged
* master

c:\src>git branch --no-merged
qc3937
qc4042

c:\src>git branch -d qc4042
error: The branch 'qc4042' is not an ancestor of your current HEAD.
If you are sure you want to delete it, run 'git branch -D qc4042'.

c:\src>git svn rebase
First, rewinding head to replay your work on top of it...
Fast-forwarded master to refs/remotes/svn/git-svn.

c:\src>git branch --merged
* master
qc4042

c:\src>git branch -d qc4042
Deleted branch qc4042 (was 6516af4).


tags: ComputersAndTechnology
comments powered by Disqus