Description Usage Arguments Details Examples
Create a new local branch. You must specify the name of the new
branch, at the very least. By default, the new branch will point at current
HEAD. Optionally, you can specify another commit to base the branch on, via a
revision
string, e.g. HEAD^, branchname, SHA-1 or a leading
substring thereof.
1 | git_branch_create(name, repo = ".", rev = "HEAD")
|
name |
Name for the new branch |
repo |
Path to a Git repo. If unspecified, current working directory is checked to see if it is or is inside a Git repo. |
rev |
Target commit, as a
revision
string, e.g. |
Convenience wrapper around
git2r::branch_create().
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 | repo <- git_init(tempfile("githug-branches-"))
owd <- setwd(repo)
## first commit
writeLines("Well, we're not in the middle of nowhere...", "nowhere.txt")
git_commit("nowhere.txt", message = "1: not in the middle of nowhere")
git_branch_list()
## second commit
write("but we can see it from here.", "nowhere.txt", append = TRUE)
git_commit("nowhere.txt", message = "2: but we can see it from here")
## create new branch that points at HEAD = second commit
git_branch_create("carpe_diem")
git_branch_list()
## create new branch that points at *first commit*, via its SHA
(gl <- git_history())
git_branch_create("hindsight", rev = gl$sha[[2]])
git_branch_list()
## Not run:
## try to re-create an existing branch and fail
git_branch_create("hindsight")
## End(Not run)
setwd(owd)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.