Create a project from a GitHub repoSource:
Creates a new local project and Git repository from a repo on
GitHub, by either cloning or
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
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.
A string identifying the GitHub repo in one of these forms:
Browser URL, such as
HTTPS Git URL, such as
SSH Git URL, such as
In the case of a browser, HTTPS, or SSH URL, the
hostis extracted from the URL. The
REPOpart will be the name of the new local folder, which is also a project and Git repo.
The new folder is stored here. If
NULL, defaults to user's Desktop or some other conspicuous place. You can also set a default location using the option
options(usethis.destdir = "a/good/dir"), perhaps saved to your
FALSE, we clone
TRUE, we fork
repo_spec, clone that fork, and do additional set up favorable for future pull requests:
The source repo,
repo_spec, is configured as the
upstreamremote, using the indicated
DEFAULTbranch is set to track
master. It is also immediately pulled, to cover the case of a pre-existing, out-of-date fork.
fork = NA(the default), we check your permissions on
repo_spec. If you can push, we set
fork = FALSE, If you cannot, we set
fork = TRUE.
Initiate an RStudio Project? Defaults to
TRUEif in an RStudio session and project has no pre-existing
.Rprojfile. Defaults to
FALSEotherwise (but note that the cloned repo may already be an RStudio Project, i.e. may already have a
TRUE, activates the new project:
If RStudio desktop, the package is opened in a new session.
If on RStudio server, the current RStudio project is activated.
Otherwise, the working directory and active project is changed.
One of "https" or "ssh"
GitHub host to target, passed to the
gh::gh(). If unspecified, gh defaults to "https://api.github.com", although gh's default can be customised by setting the GITHUB_API_URL environment variable.
For a hypothetical GitHub Enterprise instance, either "https://github.acme.com/api/v3" or "https://github.acme.com" is acceptable.
- auth_token, 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
host, as retrieved by
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