branch_get_upstream: Get remote tracking branch

Description Usage Arguments Value Examples

View source: R/branch.R

Description

Get remote tracking branch, given a local branch.

Usage

1

Arguments

branch

The branch

Value

git_branch object or NULL if no remote tracking branch.

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
## Not run: 
## Initialize two temporary repositories
path_bare <- tempfile(pattern="git2r-")
path_repo <- tempfile(pattern="git2r-")
dir.create(path_bare)
dir.create(path_repo)
repo_bare <- init(path_bare, bare = TRUE)
repo <- clone(path_bare, path_repo)

## Config user and commit a file
config(repo, user.name = "Alice", user.email = "alice@example.org")

## Write to a file and commit
lines <- "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do"
writeLines(lines, file.path(path_repo, "example.txt"))
add(repo, "example.txt")
commit(repo, "First commit message")

## Push commits from repository to bare repository
## Adds an upstream tracking branch to branch 'master'
push(repo, "origin", "refs/heads/master")

## Get remote tracking branch
branch_get_upstream(repository_head(repo))

## End(Not run)

Example output

cloning into '/work/tmp/tmp/Rtmp5YkE35/git2r-2a15e541c927da'...
[855d9ae] 2021-02-10: First commit message
[855d9a] (origin @ /work/tmp/tmp/Rtmp5YkE35/git2r-2a15e512686549) master

git2r documentation built on Nov. 22, 2021, 9:08 a.m.