Skip to content

Branches

Branch operations are available via repo.branches.

// Local branches
let locals = try repo.branches.list()
// Remote branches
let remotes = try repo.branches.list(type: .remote)
// All
let all = try repo.branches.list(type: .all)

Each item is a Branch with .name, .shortName, and .isHead.

let commit = try repo.log(limit: 1).first!
let branch = try repo.branches.create(named: "feature/my-feature", at: commit)
try repo.branches.checkout(named: "feature/my-feature")
try repo.branches.delete(named: "feature/my-feature")
try repo.branches.rename("old-name", to: "new-name")
let branches = try repo.branches.list()
let current = branches.first(where: { $0.isHead })
print(current?.shortName ?? "detached HEAD")