1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/branch.R
\name{branch_create}
\alias{branch_create}
\title{Create a branch}
\usage{
branch_create(commit = last_commit(), name = NULL, force = FALSE)
}
\arguments{
\item{commit}{Commit to which the branch should point. The default
is to use the \code{last_commit()} function to determine the
commit to which the branch should point.}
\item{name}{Name for the branch}
\item{force}{Overwrite existing branch. Default = FALSE}
}
\value{
invisible git_branch object
}
\description{
Create a branch
}
\examples{
\dontrun{
## Initialize a temporary repository
path <- tempfile(pattern="git2r-")
dir.create(path)
repo <- init(path)
## Create a user and commit a file
config(repo, user.name = "Alice", user.email = "alice@example.org")
lines <- "Hello world!"
writeLines(lines, file.path(path, "example.txt"))
add(repo, "example.txt")
commit_1 <- commit(repo, "First commit message")
## Create a branch
branch_1 <- branch_create(commit_1, name = "test-branch")
## Add one more commit
lines <- c("Hello world!", "HELLO WORLD!")
writeLines(lines, file.path(path, "example.txt"))
add(repo, "example.txt")
commit_2 <- commit(repo, "Another commit message")
## Create a branch with the same name should fail
try(branch_create(commit_2, name = "test-branch"), TRUE)
## Force it
branch_2 <- branch_create(commit_2, name = "test-branch", force = TRUE)
}
}
|