Session - Getting started with Git and GitHub
Configure user.name
and user.email
Ask for a situation report.
A lot of information will appear in the RStudio Console!
Git config (global)
• Name: <unset>
• Email: <unset>
• Global (user-level) gitignore file: <unset>
• Vaccinated: FALSE
ℹ See `?git_vaccinate` to learn more
ℹ Defaulting to 'https' Git protocol
• Default Git protocol: 'https'
• Default initial branch name: <unset>
GitHub
• Default GitHub host: 'https://github.com'
• Personal access token for 'https://github.com': <unset>
• To create a personal access token, call `create_github_token()`
• To store a token for current and future use, call `gitcreds::gitcreds_set()`
ℹ Read more in the 'Managing Git(Hub) Credentials' article:
https://usethis.r-lib.org/articles/articles/git-credentials.html
Git repo for current project
• Active usethis project: '/cloud/project'
ℹ Active project is not a Git repo
Adds .DS_Store, .Rproj.user, .Rdata, .Rhistory, and .httr-oauth to your global (a.k.a. user-level) .gitignore. This is good practice as it decreases the chance that you will accidentally leak credentials to GitHub. git_vaccinate() also tries to detect and fix the situation where you have a global gitignore file, but it’s missing from your global Git config.
Communicating with GitHub will require authentication
Instead of typing in your username and password each time, use a PAT (personal access token)
connect-posit-github
PAT tokens on the cloud
When you use the following code you’ll get a prompt, copy the token with no quotes.
Deleting a PAT
If you are using the Cloud or want to delete the PAT from your system use gitcreds::gitcreds_delete()
To make our project a Git repository, or ‘repo’ on our local machine we use
A word on R Projects
✔ Initialising Git repo
Error: Path 'C:/Users/zoe.turner/OneDrive - Midlands and Lancashire CSU/Documents/' does not appear to be inside a project or package.
Read more in the help for `proj_get()`.
.Rproj
file set up for Projects√ Initialising Git repo
√ Adding '.Rdata', '.httr-oauth', '.DS_Store' to '.gitignore'
There are 2 uncommitted files:
• '.gitignore'
• 'git_project.Rproj'
Is it ok to commit them?
1: Yeah
2: Absolutely not
3: No
Changing selections
Choose the positive option (these change so might say I agree
instead of Yes
)
√ Adding files
√ Commit with message 'Initial commit'
• A restart of RStudio is required to activate the Git pane
Restart now?
1: Nope
2: Definitely
3: No
.Rdata
can be either no for this, more info at intro-r course
.gitignore
will appear in the Files paneTo create a copy on GitHub
This will open up the GitHub page in your default browser
If you get this:
✔ Checking that current branch is 'main'
Which git protocol to use? (enter 0 to exit)
1: ssh <-- presumes that you have set up ssh keys
2: https <-- choose this if you don't have ssh keys (or don't know if you do)
Choose 2 at the moment.
ℹ Defaulting to 'https' Git protocol
✔ Setting active project to '/cloud/project'
✔ Creating GitHub repository 'Lextuga007/project'
✔ Setting remote 'origin' to 'https://github.com/Lextuga007/project.git'
✔ Pushing 'master' branch to GitHub and setting 'origin/master' as upstream branch
✔ Opening URL 'https://github.com/Lextuga007/project'
The branch is called master
here as default but conventionally people have moved to main
To rename this branch:
Details of where the change has occurred
Repeat the code and a different message appears
✖ It's weird that the current default branch for your local repo and the source repo are different:
'master' (local) != 'main' (source)
Are you sure you want to proceed?
1: yes
2: no
This is our first insight into how Git sees local and remote as two separate things!
This won’t affect other projects in the cloud but is useful on a computer
If you want to update a lot of old repository default branches from master
to main
this can be done using a Shiny app built by Garrick Aden-Buie, Software Engineer for Shiny at Posit.
These slides were designed by Mine Çetinkaya-Rundel and Emma Rand for the Forwards Package development module course
Your first package and Setting up your system
CDU Data Science Personal Access Tokens blog