repo <- git_init(tempfile("githug-"))
owd <- setwd(repo)
## no commits --> no branches
git_branch_list()
## commit and ... now we have master
writeLines("Well, we're not in the middle of nowhere...", "nowhere.txt")
git_COMMIT('1: not in the middle of nowhere')
git_branch_list()
git_branch_list(tips = TRUE)
## create new branch that points at HEAD
git_branch_create("earlybranch")
git_branch_list()
## another commit
write("but we can see it from here.", "nowhere.txt", append = TRUE)
git_COMMIT('2: but we can see it from here')
## create new branch that points at *first commit*, not HEAD
(gl <- git_log())
git_branch_create("hindsight", commit = gl$commit[[2]])
git_branch_list()
git_branch_list(tips = TRUE)
## Not run:
# ## try to re-create an existing branch and fail
# git_branch_create("hindsight")
# ## End(Not run)
## try try again ... and use the force = TRUE
git_branch_create("hindsight", force = TRUE)
git_branch_list(tips = TRUE)
## checkout an existing branch
git_checkout("earlybranch")
git_branch()
git_HEAD()
## checkout master
git_checkout()
git_HEAD()
## checkout AND CREATE all at once
git_CHECKOUT("IMMEDIATE-GRATIFICATION")
git_HEAD()
## delete a branch
git_branch_delete("earlybranch")
git_branch_list()
setwd(owd)
Run the code above in your browser using DataLab