Happy Git with R

Happy Git with R
Author

Yingchao Zhou

Published

February 2, 2023

Prompt:

git and Github are tools for helping with versioning of files in collaborative efforts as well as archiving entries for your future self. Unfortunately working with git isn’t always completely straightforward. Jenny Bryan’s book “Happy git and github with R” helps with that. The book is available from http://happygitwithr.com/. Have a look over the index and pick one of the chapters for a more in-depth read.

Write a blog post answering the following questions:

  1. Write a short (100-150 words) summary of the chapter you read in-depth.

I read the chapter “9. Personal access token for HTTPS”.

This chapter mainly teaches us how to set up a personal access token (PAT) to allow the local computer talk to the GitHub. Note the password for login on GitHub is not an acceptable credential.

The whole generating and storing process may be done through R package usethis. Commands usethis::create_github_token() will generate the PAT and gitcreds::gitcreds_set() can store the credential.

You may also generate the PAT on https://github.com/settings/tokens and store the token generated at a secure place.

Bu default, the APT will expire in 30 days. And you need to re-generate and re-store the APT in the same steps.

  1. Looking back at all of the team projects you have been involved in, describe the biggest mishap you had. Could that have been avoided using git? How?.

It was a mess…

I once worked with a classmate. We had a Github repository but I didn’t know how to push the changes from Rstudio or terminal, so every time I actually only committed the changes without pushing them to Github. I also occasionally uploaded my R script to Github page.

However, once after I made a major change, I didn’t upload my file in a timely manner and my classmate worked with the wrong code for a day. When they taught me how to push to Github after this, the main branch was several steps ahead due to me uploading .R file. We had to force the push and lost some commits.
Unfortunately, it turned out that we needed some old code that we lost in that force push… And we had to take some trouble to recover the commits.

If I had learned how to push from Rstudio (or just terminal) and only updated the code through push, we would have a clean record of the code.

  1. Give an example of one new git feature that you learned about from Jenny Bryan’s book..

You may use git remote set-url to change between https://github.com/usr/project.git and git@github.com:usr/project.git and switch between HTTPS and SSH credentials. (I currently use SSH. It’s good to know I can switch freely.)