def delete_branch(delete_branchname, force=False, remote=None, verbose=0):
    '''delete a branch.  
    if remote=True, then look in refs/remotes, otherwise check refs/heads
    for local, check if it has a remote tracking branch, and only allow delete if upstream has merged
    '''
    print('delete', delete_branchname, force, remote)
    repo = _get_repo()
    if remote:
        qualified_branch = repo._format_ref_remote(delete_branchname)
    else:
        qualified_branch = repo._format_ref_branch(delete_branchname)
        if delete_branchname == repo.active_branch:
            GitError('Cannot delete active branch.  ')

    remote_tracking_branch = get_remote_tracking_branch(repo, delete_branchname)

    if remote_tracking_branch and not force:
        #see if local is ahead of remote
        commits_ahead = count_commits_between(repo,
                                              repo.refs[qualified_branch],
                                              repo.remote_branches[remote_tracking_branch])[0]
        if commits_ahead:
            raise GitError(
                '{0} is ahead of {1} by {2} commits.\nuse git branch -D\n'.format(
                    delete_branchname,
                    remote_tracking_branch,
                    commits_ahead
                )
            )
    print('removing {} (was {})\n'.format(delete_branchname, repo.refs[qualified_branch]))
    del repo.repo.refs[qualified_branch]

    if not remote:
        remove_tracking(delete_branchname)
    #todo reflog
delete a branch.  
    if remote=True, then look in refs/remotes, otherwise check refs/heads
    for local, check if it has a remote tracking branch, and only allow delete if upstream has merged
    
lib/git/git-branch.py