Create a project from a GitHub repo
Creates a new local project and Git repository from a repo on GitHub, by
either cloning or
fork-and-cloning. In the
fork-and-clone case, create_from_github()
also does additional remote and
branch setup, leaving you in the perfect position to make a pull request with
pr_init()
, one of several functions that work pull requests.
create_from_github()
works best when your GitHub credentials are
discoverable. See below for more about authentication.
create_from_github( repo_spec, destdir = NULL, fork = NA, rstudio = NULL, open = rlang::is_interactive(), protocol = git_protocol(), host = NULL, auth_token = deprecated(), credentials = deprecated() )
repo_spec |
A string identifying the GitHub repo in one of these forms:
In the case of a browser, HTTPS, or SSH URL, the |
destdir |
The new folder is stored here. If |
fork |
If
If |
rstudio |
Initiate an RStudio Project?
Defaults to |
open |
If
|
protocol |
One of "https" or "ssh" |
host |
GitHub host to target, passed to the For a hypothetical GitHub Enterprise instance, either "https://github.acme.com/api/v3" or "https://github.acme.com" is acceptable. |
auth_token |
: No longer
consulted now that usethis uses the gert package for Git operations,
instead of git2r; gert relies on the credentials package for auth. The API
requests are now authorized with the token associated with the |
credentials |
: No longer
consulted now that usethis uses the gert package for Git operations,
instead of git2r; gert relies on the credentials package for auth. The API
requests are now authorized with the token associated with the |
Many usethis functions, including those documented here, potentially interact with GitHub in two different ways:
Via the GitHub REST API. Examples: create a repo, a fork, or a pull request.
As a conventional Git remote. Examples: clone, fetch, or push.
Therefore two types of auth can happen and your credentials must be discoverable. Which credentials do we mean?
A GitHub personal access token (PAT) must be discoverable by the gh
package, which is used for GitHub operations via the REST API. See
gh_token_help()
for more about getting and configuring a PAT.
If you use the HTTPS protocol for Git remotes, your PAT is also used for
Git operations, such as git push
. Usethis uses the gert package for this,
so the PAT must be discoverable by gert. Generally gert and gh will
discover and use the same PAT. This ability to "kill two birds with one
stone" is why HTTPS + PAT is our recommended auth strategy for those new
to Git and GitHub and PRs.
If you use SSH remotes, your SSH keys must also be discoverable, in addition to your PAT. The public key must be added to your GitHub account.
Git/GitHub credential management is covered in a dedicated article: Managing Git(Hub) Credentials
use_github()
to go the opposite direction, i.e. create a GitHub repo
from your local repo
git_protocol()
for background on protocol
(HTTPS vs SSH)
use_course()
to download a snapshot of all files in a GitHub repo,
without the need for any local or remote Git operations
## Not run: create_from_github("r-lib/usethis") # repo_spec can be a URL create_from_github("https://github.com/r-lib/usethis") # a URL repo_spec also specifies the host (e.g. GitHub Enterprise instance) create_from_github("https://github.acme.com/OWNER/REPO") ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.