2023-10-10
Git is version control software
You can think of it kind of like the “track comments” function in MS Word or Google Docs, but for code (plain text)
An online tool for managing projects that use Git
Acts like a cloud backup tool for your code
Makes it easy to share code with others
A PAT is a “Personal Access Token”. It is like an extra-secure password.
There is another method for authentication called SSH, but it’s a bit more complicated to set up. If you want to use SSH, see these instructions.
Or, from R, first install usethis
with install.packages("usethis")
, then do
usethis::create_github_token()
Look over the scopes (permissions); “repo”, “user”, and “workflow” are recommended. Recommended scopes will be pre-selected if you used create_github_token()
.
Click “Generate token”.
Copy the generated PAT to your clipboard. DON’T CLOSE THE BROWSER WINDOW YET.
Install gitcreds in R with install.packages("gitcreds")
Next, run gitcreds::gitcreds_set()
.
Enter the PAT that you copied from GitHub. Now you can close the browser window.
Done!
Your PAT will expire (after 30 days by default).
You then need to re-create a new one on GitHub and enter it again with gitcreds::gitcreds_set()
.
Using an expiration date is recommended for security
You need to let git know your GitHub username and email address:
Git can allow you to have multiple versions of your code at the same time.
These are called “branches”.
Tell git to use the name “main” for the main branch:
git tracks the content of a repo
A local repo is just the project on your own computer
A remote repo is a copy of the repo online (on GitHub)
origin
Sometimes, you want to download a repo that doesn’t exist on your computer yet.
Once you have the repos set up, you need to keep them in sync.
You push changes from your local repo to the remote
You pull changes from the remote repo to your local one
There are two steps to making a commit.
A file that has been changed is not automatically added to git’s history.
You need to stage the file (or part of the file) that you want to add to a particular commit
Next, you type a short message describing the change, the commit message
Finally, you commit the change to log it in git’s history
.gitignore
fileIf there are any files you don’t want git to track, you can ignore them by listing them in a special file called .gitignore
.
It is usually a good idea to ignore raw data files and output files. We only want to track code (in other words, the analysis itself)
We will go through a typical git workflow together in class using RStudio.
This is explained in the “Intro to Git” markdown file, which you will copy to your computer when you clone the Day 2 repo.