{"id":18174425,"url":"https://github.com/r-lib/gitcreds","last_synced_at":"2025-04-04T06:06:49.434Z","repository":{"id":43260023,"uuid":"288971382","full_name":"r-lib/gitcreds","owner":"r-lib","description":"Query git credentials from R","archived":false,"fork":false,"pushed_at":"2024-11-09T13:39:36.000Z","size":2144,"stargazers_count":28,"open_issues_count":15,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T15:25:36.320Z","etag":null,"topics":["credentials","credentials-helper","git","github","r"],"latest_commit_sha":null,"homepage":"https://gitcreds.r-lib.org/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-lib.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-20T10:04:48.000Z","updated_at":"2024-10-29T13:14:56.000Z","dependencies_parsed_at":"2024-12-20T20:13:29.776Z","dependency_job_id":"4b675cff-abe5-4407-bff4-9f1a89d9afbb","html_url":"https://github.com/r-lib/gitcreds","commit_stats":{"total_commits":158,"total_committers":6,"mean_commits":"26.333333333333332","dds":"0.10759493670886078","last_synced_commit":"cf006f0ae28d62ad2f9d24b03bbd0e99f7770764"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fgitcreds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fgitcreds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fgitcreds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fgitcreds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/gitcreds/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247128744,"owners_count":20888235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["credentials","credentials-helper","git","github","r"],"created_at":"2024-11-02T16:03:06.510Z","updated_at":"2025-04-04T06:06:49.412Z","avatar_url":"https://github.com/r-lib.png","language":"R","readme":"---\noutput: github_document\n---\n\n```{r, setup, echo = FALSE, message = FALSE}\nknitr::opts_chunk$set(\n  comment = \"#\u003e\",\n  tidy = FALSE,\n  error = FALSE,\n  fig.width = 8,\n  fig.height = 8)\n```\n\n# gitcreds\n\n\u003e Query git credentials from R\n\n\u003c!-- badges: start --\u003e\n[![R build status](https://github.com/r-lib/gitcreds/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/gitcreds/actions)\n[![Codecov test coverage](https://codecov.io/gh/r-lib/gitcreds/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/gitcreds?branch=main)\n[![R-CMD-check](https://github.com/r-lib/gitcreds/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/gitcreds/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\n## Features\n\n-   (Re)use the same credentials in command line git, R and the RStudio\n    IDE., etc. Users can set their GitHub token once and use it\n    everywhere.\n\n-   Typically more secure than storing passwords and tokens in\n    `.Renviron` files.\n\n-   gitcreds has a cache that makes credential lookup very fast.\n\n-   gitcreds supports multiple users and multiple hosts, including\n    Enterprise GitHub installations.\n\n-   If git or git credential helpers are not available, e.g. typically on\n    a Linux server, or a CI, then gitcreds can fall back to use environment\n    variables, and it still supports multiple users and hosts.\n\n## Installation\n\nInstall the package from CRAN:\n\n```{r eval = FALSE}\ninstall.packages(\"gitcreds\")\n```\n\nInstall the development version from GitHub:\n\n```{r eval = FALSE}\npak::pak(\"r-lib/gitcreds\")\n```\n\n## Usage\n\ngitcreds is typically used upstream, in R packages that need to\nauthenticate to git or GitHub. End users of these packages might still find\nit useful to call gitcreds directly, to set up their credentials, or check\nthat they have been set up correctly.\n\nYou can also use gitcreds in an R script. In this case you are both the\nend user and the upstream developer.\n\n### Usage as an end user\n\n```r\nlibrary(gitcreds)\n```\n\nUse `gitcreds_get()` to check your GitHub or other git credentials.\nIt returns a named list, with a `password` entry. The password is not\nprinted by default:\n\n```r\ngitcreds_get()\n```\n\n```r\n#\u003e \u003cgitcreds\u003e\n#\u003e   protocol: https\n#\u003e   host    : github.com\n#\u003e   username: gaborcsardi\n#\u003e   password: \u003c-- hidden --\u003e\n```\n\nUse `gitcreds_set()` to add new credentials, or replace existing ones.\nIt always asks you before replacing existing credentials:\n\n```r\ngitcreds_set()\n```\n\n```r\n#\u003e -\u003e Your current credentials for 'https://github.com':\n#\u003e \n#\u003e   protocol: https\n#\u003e   host    : github.com\n#\u003e   username: gaborcsardi\n#\u003e   password: \u003c-- hidden --\u003e\n#\u003e \n#\u003e -\u003e What would you like to do?\n#\u003e \n#\u003e 1: Keep these credentials\n#\u003e 2: Replace these credentials\n#\u003e 3: See the password / token\n#\u003e \n#\u003e Selection: 2\n#\u003e \n#\u003e ? Enter new password or token: secret\n#\u003e -\u003e Removing current credentials...\n#\u003e -\u003e Adding new credentials...\n#\u003e -\u003e Removing credentials from cache...\n#\u003e -\u003e Done.\n```\n\nUse `gitcreds_delete()` to delete credentials. It always asks you before\nactually deleting any credentials:\n\n```r\ngitcreds_delete()\n```\n\n```r\n#\u003e -\u003e Your current credentials for 'https://github.com':\n#\u003e \n#\u003e   protocol: https\n#\u003e   host    : github.com\n#\u003e   username: token\n#\u003e   password: \u003c-- hidden --\u003e\n#\u003e \n#\u003e -\u003e What would you like to do?\n#\u003e \n#\u003e 1: Keep these credentials\n#\u003e 2: Delete these credentials\n#\u003e 3: See the password / token\n#\u003e \n#\u003e Selection: 2\n#\u003e -\u003e Removing current credentials...\n#\u003e -\u003e Removing credentials from cache...\n#\u003e -\u003e Done.\n```\n\n### Usage as a package author\n\nIf you want to use git's credentials in your package, call `gitcreds_get()`.\nYou probably want to handle the various errors it can return. Here is an\nexample for a function that optionally neeeds a GitHub token. It searches\nthe code of a GitHub repository:\n\n```r\ngithub_search \u003c- function(query, repo = \"wch/r-source\") {\n  token \u003c- tryCatch(\n    gitcreds::gitcreds_get(),\n    error = function(e) NULL\n  )\n\n  url \u003c- \"https://api.github.com/search/code\"\n  q \u003c- list(q = paste0(query, \"+repo:\", repo))\n  token \u003c- paste0(\"token \", token$password)\n\n  httr::GET(url, query = q, httr::add_headers(Authorization = token))\n}\n```\n\nThe next example always needs a GitHub token, so it fails without one.\nIt lists the public repositories of the current user:\n\n```r\nmsg \u003c- function(wh) {\n  msgs \u003c- c(\n    no_git = paste0(\n      \"No git installation found. You need to install git and set up \",\n      \"your GitHub Personal Access token using `gitcreds::gitcreds_set()`.\"),\n    no_creds = paste0(\n      \"No git credentials found. Please set up your GitHub Personal Access \",\n      \"token using `gitcreds::gitcreds_set()`.\")\n    )\n  msgs[wh]\n}\n\nmy_private_repos \u003c- function() {\n  token \u003c- tryCatch(\n    gitcreds::gitcreds_get(),\n    gitcreds_nogit_error = function(e) stop(msg(\"no_git\")),\n    gitcreds_no_credentials = function(e) stop(msg(\"no_creds\"))    \n  )\n\n  url \u003c- \"https://api.github.com/user/repos\"\n  q \u003c- list(visibility = \"public\")\n  token \u003c- paste0(\"token \", token$password)\n\n  httr::GET(url, query = q, httr::add_headers(Authorization = token))\n}\n```\n\nPoint your users to `gitcreds_set()` for adding/updating their credentials,\nor write your own wrapper for this.\n\nIf you want more control or a different UI, take a look at the lower level\n`gitcreds_fill()`, `gitcreds_approve()` and `gitcreds_reject()` functions.\n\nSee also [gitcreds for package authors](https://gitcreds.r-lib.org/articles/package.html).\n\n## Code of Conduct\n\nPlease note that the gitcreds project is released with a\n[Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html).\nBy contributing to this project, you agree to abide by its terms.\n\n## License\n\nMIT © [RStudio](https://github.com/rstudio)\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fgitcreds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Fgitcreds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fgitcreds/lists"}