githug (version 0.0.0.9000)

githug-branch: Report current or list all branches

Description

Report which branch you're currently on or list all local and/or remote branches in the repository.

Usage

git_branch(where = NULL, repo = ".")
git_branch_current(repo = ".")
git_branch_list(where = c("local", "all", "remote"), repo = ".")

Arguments

where
Which branches to list: local only (the default), all, 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.

git_branch

If called with no arguments, or with only the repo argument, git_branch() reports the name of the current branch. This is equivalent to calling git_branch_current() directly. If the where argument is given, its value is passed through to git_branch_list().

git_branch_current

git_branch() tells which branch you're currently on.

git_branch_list

git_branch_list() returns a data frame of information provided by git2r::branches(). How it corresponds to command line Git:

Examples

Run this code
repo <- git_init(tempfile("githug-branches-"))
owd <- setwd(repo)

## no commits --> no branches
git_branch()
git_branch_list()

## commit and ... now we have master
write("Well, we're not in the middle of nowhere,", "nowhere.txt")
git_commit(all = TRUE, message = "1ouise: not in the middle of nowhere")
git_branch()
git_branch_list()

## make a new commit then checkout initial commit, thereby detaching HEAD
write("but we can see it from here.", "nowhere.txt", append = TRUE)
git_commit(all = TRUE, message = "louise: but can see it")
## TODO: come back and make this nicer when more functions exist
init_commit <- as.git_commit(git_revision("HEAD^"))
git2r::checkout(init_commit)
git_branch()
git_branch_list()

setwd(owd)

Run the code above in your browser using DataCamp Workspace