Creates a new local Git repository from a repository on GitHub. It is highly recommended that you pre-configure or pass a GitHub personal access token (PAT), which is facilitated by browse_github_token(). In particular, a PAT is required in order for create_from_github() to do "fork and clone". It is also required by use_github(), which connects existing local projects to GitHub.

  destdir = NULL,
  fork = NA,
  rstudio = NULL,
  open = rlang::is_interactive(),
  protocol = git_protocol(),
  credentials = NULL,
  auth_token = github_token(),
  host = NULL



GitHub repo specification in this form: owner/repo. The repo part will be the name of the new local 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 usethis.destdir, e.g. options(usethis.destdir = "a/good/dir"), perhaps saved to your .Rprofile with edit_r_profile()


If TRUE, we create and clone a fork. If FALSE, we clone repo_spec itself. Will be set to FALSE if no auth_token (a.k.a. PAT) is provided or preconfigured. Otherwise, defaults to FALSE if you can push to repo_spec and TRUE if you cannot. In the case of a fork, the original target repo is added to the local repo as the upstream remote, using the preferred protocol. The master branch is set to track upstream/master and is immediately pulled, which matters in the case of a pre-existing, out-of-date fork.


Initiate an RStudio Project? Defaults to TRUE if in an RStudio session and project has no pre-existing .Rproj file. Defaults to FALSE otherwise.


If 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.


Optional. Should be "ssh" or "https", if specified. Defaults to the option usethis.protocol and, if unset, to an interactive choice or, in non-interactive sessions, "ssh". NA triggers the interactive menu.


A git2r credential object produced with git2r::cred_env(), git2r::cred_ssh_key(), git2r::cred_token(), or git2r::cred_user_pass().


GitHub personal access token (PAT).


GitHub API host to use. Override with the endpoint-root for your GitHub enterprise instance, for example, "".

Using SSH Keys on Windows

If you are a Windows user who connects to GitHub using SSH, as opposed to HTTPS, you may need to explicitly specify the paths to your keys and register this credential in the current R session. This helps if git2r, which usethis uses for Git operations, does not automatically find your keys or handle your passphrase.

In the snippet below, do whatever is necessary to make the paths correct, e.g., replace <USERNAME> with your Windows username. Omit the passphrase part if you don't have one. Replace <OWNER/REPO> with the appropriate GitHub specification. You get the idea.

creds <- git2r::cred_ssh_key(
  publickey  = "C:/Users/<USERNAME>/.ssh/",
  privatekey = "C:/Users/<USERNAME>/.ssh/id_rsa",
  passphrase = character(0)
use_git_credentials(credentials = creds)

  repo_spec = "<OWNER/REPO>",

See also

use_github() for GitHub setup advice. git_protocol() and git_credentials() for background on protocol and credentials. use_course() for one-time download of all files in a Git repo, without any local or remote Git operations.


if (FALSE) { create_from_github("r-lib/usethis") }