Introduction to Git and GitHub

Session - {usethis} errors

Zoë Turner

Error in “stop_bad_github_remote_config()”

If you get this

✔ Setting active project to '/cloud/project'
Error in `stop_bad_github_remote_config()`:
! Unsupported GitHub remote configuration: 'no_github'
• Host = NA
• origin = <not configured>
• upstream = <not configured>
• Neither 'origin' nor 'upstream' is a GitHub repo.

Read more about the GitHub remote configurations that usethis supports at:
'https://happygitwithr.com/common-remote-setups.html'
Run `rlang::last_trace()` to see where the error occurred.

It’s because GitHub connections (including personal access tokens) haven’t been set up. The {usethis} functions won’t work though as they require a connection to GitHub

You can use Git locally (F5 refresh in the Cloud).

If they continue

In the Terminal (starts with $ on the command line

git remote -v

Gives details of the remote branch, if nothing shows and both the push and pull buttons in RStudio are grey

git remote add origin <remote_URL>

with the url coming from the HTTPS url from GitHub’s green button Code on the repo.

Posit Cloud repos are called project

Particularly because Posit Cloud repos are called project, if you have set up a connection to GitHub before you will geta message

Error: Repo ‘Lextuga007/project’ already exists on ‘github.com’

It’s best to delete the GitHub repo (check for any work you want to keep!) and start again when using Posit Cloud.

In GitHub, under the Settings tab and scroll down to the Danger Zone. You may need to Restart the R session as a refresh.

Pop up for username for https://github.com

This is because the Personal Access Token hasn’t been set up correctly. It might have expired or deleted. Best resolved by resetting the PAT details.

Unable to confirm the GitHub remote configuration is “pull request ready”

Unable to confirm the GitHub remote configuration is "pull request ready".
You probably need to configure a personal access token for 'github.com'.
See `gh_token_help()` for help.
(Or maybe we're just offline?)
Unexpected GitHub remote configuration: 'maybe_ours_or_theirs'
Host = 'https://github.com'
origin = 'nhs-r-community/intro-git-github'
upstream = <not configured>
'origin' is a GitHub repo and 'upstream' is either not configured or is not a GitHub repo.

We may be offline or you may need to configure a GitHub personal access
token. `gh_token_help()` can help with that.

Read more about what this GitHub remote configurations means at:
'https://happygitwithr.com/common-remote-setups.html'

1: Yes, I want to proceed. I know what I'm doing.
2: No, I want to stop and straighten out my GitHub remotes first.

Trying pr_pull() may give this:

Error: Unable to get GitHub info for these remotes: 'origin'
Are we offline? Is GitHub down? Has the repo been deleted?
Otherwise, you probably need to configure a personal access token (PAT) for 'github.com'
See `?gh_token_help` for advice

which suggests the PAT has been removed/deleted or is unobtainable by the project.

It may be that an alternative place to save the PAT is needed

Storing the PAT in .Renviron

This is no longer a recommended way of saving a PAT but is required in some circumstances (linux servers)

usethis::edit_r_environ()

will open a blank document in RStudio

Text in .Renviron

With no spaces, returns or any spacing the PAT is added to the file like

GITHUB_PAT=ghp_gobbledygookgeneratedbygithub

Restart the R session (Ctrl+Shift+F10)

Running Sys.getenv("GITHUB_PAT") in the Console will show the PAT code

“Error in libgit2::git_branch_create”

With the error:

Error in libgit2::git_branch_create : the given reference name ’refs/heads/Add render specifics to _quarto.yml’ is not valid

Check that the name given in the command usethis::pr_init() is in the branch format

usethis::pr_init("update-quarto-yml")

not like a commit format (with spaces often)

usethis::pr_init("Add render specifics to _quarto.yml")

Error: The pr_*() functions facilitate pull requests.

This may be where the function pr_push() is being used but from the main branch

If changes are required (for example to reinstate the greyed out push and pull in RStudio)

On the Git Terminal (where the command line starts with $)

git push --set-upstream origin main

Refresh the RStudio git pane to ensure the buttons are no longer greyed out ## End session