Branches

To implement the behaviour of the supporting branch types that git-flow uses, so called branch managers are used. BranchManager is the abstract base class for all concrete branch managers. Each type of branch in git-flow (e.g. feature, release, hotfix and support branches) has a corresponding branch manager.

A branch manager is responsible for listing, creating, merging, deleting, finishing (i.e. merging+deleting) branches of a given type. Most of the functionality is already implemented by the base BranchManager, so that subclassing a branch manager is easy.

class gitflow.branches.BranchManager(gitflow, prefix=None)

Initializes an instance of BranchManager. A branch manager is responsible for listing, creating, merging, deleting, finishing (i.e. merging+deleting) branches of a given type.

Parameters:
  • gitflow – The gitflow.core.GitFlow instance that this branch manager belongs to.
  • prefix – The prefix to use for the type of branches that this branch manager manages. If this is not None, it supersedes the configuration of the gitflow object’s repository.
by_name_prefix(nameprefix)

If exactly one branch of the type that this manager manages starts with the given name prefix, returns that branch. Raises NoSuchBranchError in case no branches exist with the given prefix, or PrefixNotUniqueError in case multiple matches are found.

Parameters:nameprefix – The name prefix (or full name) of the short branch name to match.
Returns:The git.refs.Head instance of the branch that can be uniquely identified by the given name prefix.
create(name, base=None, fetch=False, must_be_on_default_base=False)

Creates a branch of the type that this manager manages and checks it out.

Parameters:
  • name – The (short) name of the branch to create.
  • base – The base commit or ref to base the branch off from. If a base is not provided explicitly, the default base for this type of branch is used. See also default_base().
  • fetch – If set, update the local repo with remote changes prior to creating the new branch.
  • must_be_on_default_base – If set, the base must be a valid commit on the branch manager default_base.
Returns:

The newly created git.refs.Head reference.

default_base()
Returns:The name of branch to use as the default base for branching off from in case no explicit base is specified.

This method can be overriden in a subclass of BranchManager. If not overriden, the default is to use the ‘develop’ branch.

delete(name, force=False)

This deletes a branch of the type that this manager manages named name.

Parameters:
  • name – The (short) name of the branch to delete.
  • force – Delete the branch, even if this would lead to data loss.
iter()
Returns:

An iterator, iterating over all branches of the type that this manager manages.

list()
Returns:

A list of all branches of the type that this manager manages. See also iter().

merge(name, into, message=None)

This merges the branch named name into the branch named into, using commit message message.

Parameters:
  • name – The (short) name of the branch that needs merging. Alternatively this is a instance of git.Reference (or subclass).
  • into – The name of the branch to merge into.
  • message

    The commit message to use for the merge commit. If it is not given, a default merge message is used. You can use the following string placeholders, which merge() will expand:

    %(name)s = The full name of the branch (e.g. 'feature/foo')
    %(short_name)s = The friendly name of the branch (e.g. 'foo')
    %(identifier)s = The type (e.g. 'feature', 'hotfix', etc.)

You typically don’t need to override this method in a subclass.

shorten(full_name)

Returns the friendly (short) name of this branch, without the prefix, given the fully qualified branch name.

Parameters:full_name – The full name of the branch as it is known to Git, including the prefix.
Returns:The friendly name of the branch.

Previous topic

Core git-flow