Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.62 KB

branch.md

File metadata and controls

65 lines (46 loc) · 1.62 KB

Branch

To access a Branch, starting from a repository object:

use Gitonomy\Git\Repository;

$repository = new Repository('/path/to/repository');
$branch = $repository->getReferences()->getBranch('master');
$remoteBranch = $repository->getReferences()->getRemoteBranch('origin/master');

See references.md to list, create and delete branches.

You can check if the branch is a local or a remote one:

$branch->isLocal();  // A branch of refs/heads/
$branch->isRemote(); // A branch of refs/remotes/, like origin/master

$branch->getName(); // "master", or "origin/master" for a remote branch

Like every reference, a branch gives its commit:

$commit = $branch->getCommit();
$hash = $branch->getCommitHash();

Moving a branch

moveTo() points the branch to a revision: a name, a hash, or a Revision object. It returns the branch, read again: the object you called it on keeps the commit it pointed to.

$branch = $branch->moveTo('master~2');

Like git update-ref, it doesn't touch the working tree, even for the branch checked out.

Merged branches

isMergedInto() tells if the history of a revision (a name, a hash, or a Revision object) contains the branch:

if ($branch->isMergedInto('master')) {
    echo $branch->getName().' is merged into master'.PHP_EOL;
}

Branches containing a commit

To find the branches whose history contains a commit, use Commit::getIncludingBranches(): see commit.md.

To check a branch out, see workingcopy.md.