usethis (version 2.2.3)

use_git_remote: Configure and report Git remotes

Description

Two helpers are available:

  • use_git_remote() sets the remote associated with name to url.

  • git_remotes() reports the configured remotes, similar to git remote -v.

Usage

use_git_remote(name = "origin", url, overwrite = FALSE)

git_remotes()

Value

Named list of Git remotes.

Arguments

name

A string giving the short name of a remote.

url

A string giving the url of a remote.

overwrite

Logical. Controls whether an existing remote can be modified.

Examples

Run this code
if (FALSE) {
# see current remotes
git_remotes()

# add new remote named 'foo', a la `git remote add  `
use_git_remote(name = "foo", url = "https://github.com//.git")

# remove existing 'foo' remote, a la `git remote remove `
use_git_remote(name = "foo", url = NULL, overwrite = TRUE)

# change URL of remote 'foo', a la `git remote set-url  `
use_git_remote(
  name = "foo",
  url = "https://github.com//.git",
  overwrite = TRUE
)

# Scenario: Fix remotes when you cloned someone's repo, but you should
# have fork-and-cloned (in order to make a pull request).

# Store origin = main repo's URL, e.g., "git@github.com:/.git"
upstream_url <- git_remotes()[["origin"]]

# IN THE BROWSER: fork the main GitHub repo and get your fork's remote URL
my_url <- "git@github.com:/.git"

# Rotate the remotes
use_git_remote(name = "origin", url = my_url)
use_git_remote(name = "upstream", url = upstream_url)
git_remotes()

# Scenario: Add upstream remote to a repo that you fork-and-cloned, so you
# can pull upstream changes.
# Note: If you fork-and-clone via `usethis::create_from_github()`, this is
# done automatically!

# Get URL of main GitHub repo, probably in the browser
upstream_url <- "git@github.com:/.git"
use_git_remote(name = "upstream", url = upstream_url)
}

Run the code above in your browser using DataLab