Description Usage Arguments Value Examples
Checkout the main
or master
branch of the given Git repositories. But
stay on the current reference (e.g. branch) if checking out the repository
that called checkout()
.
1 | checkout(repos)
|
repos |
Path to one or more Git repositories. |
Called for its side effect. Returns repos
invisibly.
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 | library(magrittr)
# Helper
walk <- function(x, f, ...) {
lapply(x, f, ...)
invisible(x)
}
# Setup two minimal repositories.
repos <- file.path(tempdir(), paste0("repo", 1:2))
repos
repos %>% walk(dir.create)
repos %>%
file.path("a-file.txt") %>%
walk(file.create)
repos %>%
walk_git("init") %>%
walk_git("config user.name Jerry") %>%
walk_git("config user.email jerry@gmail.com") %>%
walk_git("add .") %>%
walk_git("commit -m 'New file'")
# If we set the directory at `repo1`, it stays at the branch `pr`, whereas the
# `repo2` changes to the branch `master` (or `main`).
oldwd <- getwd()
setwd(repos[[1]])
repos %>% walk_git("checkout -b pr")
# Compare before and after `checkout()`
repos %>% walk_git("branch", verbose = TRUE)
repos %>% checkout()
repos %>% walk_git("branch", verbose = TRUE)
# Cleanup
setwd(oldwd)
repos %>% walk(unlink, recursive = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.