Skip to content

Commit d603879

Browse files
committed
docs: add examples for git branches, basic and orphan
1 parent e2afcf9 commit d603879

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

R/branch.R

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,65 @@ git_branch_list <- function(local = NULL, repo = '.') {
3030
#' @param orphan if branch does not exist, checkout unborn branch
3131
#' @useDynLib gert R_git_checkout_branch R_git_checkout_unborn
3232
#' @git checkout
33+
#' @param force overwrite existing branch
34+
#' @examplesIf interactive()
35+
#' # Creating a branch
36+
#' repo <- file.path(tempdir(), "myrepo")
37+
#' git_init(repo)
38+
#' writeLines("hello", file.path(repo, "hello.txt"))
39+
#' git_add("hello.txt", repo = repo)
40+
#' first_commit <- git_commit("First commit", repo = repo)
41+
#'
42+
#' git_branch_create("new-feat", repo = repo)
43+
#' writeLines("world", file.path(repo, "hello.txt"))
44+
#' git_add("hello.txt", repo = repo)
45+
#' second_commit <- git_commit("Second commit", repo = repo)
46+
#'
47+
#' # Changing branches
48+
#' git_branch(repo = repo)
49+
#' git_branch_switch("main", repo = repo)
50+
#' git_branch(repo = repo)
51+
#'
52+
#' git_branch_exists("new-feat", repo = repo)
53+
#'
54+
#' # Listing branches
55+
#' git_branch_list(repo = repo)
56+
#'
57+
#' # Renaming a branch
58+
#' git_branch_move("new-feat", "better-name", repo = repo)
59+
#' git_branch_exists("new-feat", repo = repo)
60+
#' git_branch_list(repo = repo)
61+
#'
62+
#' # Deleting a branch
63+
#' git_branch_delete("better-name", repo = repo)
64+
#' git_branch_exists("better-name", repo = repo)
65+
#'
66+
#' # clean up
67+
#' unlink(repo, recursive = TRUE)
68+
#' # ------------------------
69+
#' # Creating an orphan branch
70+
#' repo <- file.path(tempdir(), "myrepo")
71+
#' git_init(repo)
72+
#'
73+
#' # Set a user if no default
74+
#' if (!user_is_configured()) {
75+
#' git_config_set("user.name", "Jerry")
76+
#' git_config_set("user.email", "jerry@gmail.com")
77+
#' }
78+
#' writeLines("hello", file.path(repo, "hello.txt"))
79+
#' git_add("hello.txt", repo = repo)
80+
#' first_commit <- git_commit("First commit", repo = repo)
81+
#'
82+
#' writeLines("world", file.path(repo, "hello.txt"))
83+
#' git_add("hello.txt", repo = repo)
84+
#' second_commit <- git_commit("Second commit", repo = repo)
85+
#'
86+
#' # Check out first commit
87+
#' git_branch_checkout(first_commit, orphan = TRUE, repo = repo)
88+
#' git_status(repo)
89+
#' # clean up
90+
#' unlink(repo, recursive = TRUE)
91+
#'
3392
git_branch_checkout <- function(
3493
branch,
3594
force = FALSE,

man/git_branch.Rd

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)