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_pat(). 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. use_github() has more detailed advice on working with the protocol and credentials arguments.

create_from_github(repo_spec, destdir = NULL, fork = NA,
  rstudio = NULL, open = interactive(), protocol = c("ssh", "https"),
  credentials = NULL, auth_token = NULL, 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. Defaults to user's Desktop.


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. If a fork is created, the original target repo is added to the local repo as the upstream remote, using your preferred protocol, to make it easier to pull upstream changes in the future.


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 and in RStudio, a new RStudio project is opened in a new instance, if possible, or is switched to, otherwise. If TRUE and not in RStudio (or new project is not an RStudio project), working directory is set to the new project.


transfer protocol, either "ssh" (the default) or "https"


A git2r::cred_ssh_key() specifying specific ssh credentials or NULL for default ssh key and ssh-agent behaviour.


Provide a personal access token (PAT) from If NULL, will use the logic described in gh::gh_whoami() to look for a token stored in an environment variable. Use browse_github_pat() to help set up your PAT.


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

See also

use_github() for GitHub setup advice. use_course() for one-time download of all files in a Git repo, without any local or remote Git operations.



create_from_github("r-lib/usethis", protocol = "https")

## various ways code can look when specifying ssh credential explicitly
create_from_github("r-lib/usethis", credentials = git2r::cred_ssh_key())

cred <- git2r::cred_ssh_key(
  publickey = "path/to/",
  privatekey = "path/to/id_rsa"
create_from_github("cran/TailRank", credentials = cred)
# }