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)
Run the code above in your browser using DataCamp Workspace