githug-branches: List, create, checkout, or delete branches

Description Usage Arguments git_branch_list git_branch git_branch_create git_branch_delete git_checkout git_CHECKOUT Examples

Description

Convenience wrappers around branch-related functions from git2r.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
git_branch_list(which = c("all", "local", "remote"), repo = ".",
  tips = FALSE)

git_branch(repo = ".")

git_branch_create(name, repo = ".", ...)

git_branch_delete(name, repo = ".", ...)

git_checkout(name = "master", repo = ".", ...)

git_CHECKOUT(name, repo = ".", ...)

Arguments

which

Which branches to list: all (the default), local only, or remote only.

repo

Path to a Git repo. If unspecified, current working directory is checked to see if it is or is inside a Git repo.

tips

Logical. Adds information from git_log on the commit currently at the tip of each branch. Defalts to FALSE.

name

Name of the branch.

...

Additional optional arguments to pass along to git2r.

git_branch_list

git_branch_list returns a data frame of information provided by branches and head,git_repository-method from git2r and, optionally, commit information for the current branch tips from git_log.

How it corresponds to command line Git:

git_branch_list()

is like git branch -a. Lists all branches

git_branch_list("local")

is like git branch. Lists only local branches.

git_branch_list("remote")

is like git branch -r. Lists only remote branches.

Returns a data frame (or tbl_df) with one row per branch. Default variables are branch name, type (local vs remote), and a list-column of git_branch objects. If tips = TRUE, additional variables from git_log are returned, describing the the commit each branch points to at the time of the call.

git_branch

git_branch tells which branch you're on.

git_branch_create

git_branch_create creates a new local branch. You must specify the name of the new branch, at the very least. By default, will try to determine repo from current working directory, get current HEAD from that, and point the new branch there. Optionally, you can provide the path to a repo and, via ..., even other arguments to branch_create: an arbitrary git_commit object to use as the branch's starting point or force = TRUE to overwrite an existing branch.

git_branch_delete

git_branch_delete deletes an existing local branch. Specify the branch by name. This wraps branch_delete from git2r.

git_checkout

git_checkout checks out an existing local branch. Specify the branch by name or checkout master by default. This wraps git2r's checkout,git_branch-method.

git_CHECKOUT

git_CHECKOUT checks out a branch AND creates it if necessary. This wraps git2r's checkout,git_repository-method.

Examples

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)

jennybc/githug documentation built on May 19, 2019, 5:05 a.m.