1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/git.R
3\name{use_git_remote}
4\alias{use_git_remote}
5\alias{git_remotes}
6\title{Configure and report Git remotes}
7\usage{
8use_git_remote(name = "origin", url, overwrite = FALSE)
9
10git_remotes()
11}
12\arguments{
13\item{name}{A string giving the short name of a remote.}
14
15\item{url}{A string giving the url of a remote.}
16
17\item{overwrite}{Logical. Controls whether an existing remote can be
18modified.}
19}
20\value{
21Named list of Git remotes.
22}
23\description{
24Two helpers are available:
25\itemize{
26\item \code{use_git_remote()} sets the remote associated with \code{name} to \code{url}.
27\item \code{git_remotes()} reports the configured remotes, similar to
28\verb{git remote -v}.
29}
30}
31\examples{
32\dontrun{
33# see current remotes
34git_remotes()
35
36# add new remote named 'foo', a la `git remote add <name> <url>`
37use_git_remote(name = "foo", url = "https://github.com/<OWNER>/<REPO>.git")
38
39# remove existing 'foo' remote, a la `git remote remove <name>`
40use_git_remote(name = "foo", url = NULL, overwrite = TRUE)
41
42# change URL of remote 'foo', a la `git remote set-url <name> <newurl>`
43use_git_remote(
44  name = "foo",
45  url = "https://github.com/<OWNER>/<REPO>.git",
46  overwrite = TRUE
47)
48
49# Scenario: Fix remotes when you cloned someone's repo, but you should
50# have fork-and-cloned (in order to make a pull request).
51
52# Store origin = main repo's URL, e.g., "git@github.com:<OWNER>/<REPO>.git"
53upstream_url <- git_remotes()[["origin"]]
54
55# IN THE BROWSER: fork the main GitHub repo and get your fork's remote URL
56my_url <- "git@github.com:<ME>/<REPO>.git"
57
58# Rotate the remotes
59use_git_remote(name = "origin", url = my_url)
60use_git_remote(name = "upstream", url = upstream_url)
61git_remotes()
62
63# Scenario: Add upstream remote to a repo that you fork-and-cloned, so you
64# can pull upstream changes.
65# Note: If you fork-and-clone via `usethis::create_from_github()`, this is
66# done automatically!
67
68# Get URL of main GitHub repo, probably in the browser
69upstream_url <- "git@github.com:<OWNER>/<REPO>.git"
70use_git_remote(name = "upstream", url = upstream_url)
71}
72}
73