Notes on Github
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
RStudio
Using Github is the popular method of version control in RStudio. I have struggled with managing Github with RStudio. In this section, I will put together pieces from different sources to fix your issues or get started with it.
Starting a New Project
Step 1: Create a Github Repository
Go to github.com and create a new repository. Copy it’s link.
It could be private or public depending on your whims. Public repositories are public — other users can see and fork it. Forking is a fancy term for copying to their Github. Private repositories are seen only to you. I’d also recommend to add a README file. Project description goes here. Once you create your repository, copy the link to it. Not SSH link but link visible in your browser.
Step 2: Create a New R Project
In RStudio, head over to File -> New Project. In that, select the option for version control (git). Paste the link to your newly created repository.
Once you do that, the newly created project will be synced with Github repository. You can make changes and then “commit” to your online repository.
Step 3: Commit Changes!
The last step is to create files that you want.
Finally, commit the changes.
In the top right corner of RStudio, tick all the changes you want to commit. Then add a message to the “commit message” box in the top right corner. This message is a record of what changes you did. (My advice is to use this to explain your intent rather than explain the changes. Changes are trivial to trace thanks to Git, but “why” is easy to forget.)
You’ll have the results available (almost) immediately.
Handling Passwords
If you are starting a project, jump to this. If you had a project that used password for commits (discontinued today, Aug 13 2021), jump to the first article. If it still does not resolve your issues, try the next three in that order.
- Simplest Guide on Github with R This literally solves more than 80 per cent of my problems.
Undo git commit in RStudio for more than 100 mb files
Every once in a while, you will end up trying to upload something in your local files that you do not want to commit to Github repository. How do you release that commit from R Studio? Github has a hard limit of 100 mb per file and I occasionally fail trying to upload it. Analysis paralysis.
TL;DR
- Ensure you only have commits that you want to delete in the Git pane. Then go to Git tab.
- Click on (machine-like icon) and select “Shell…”.
- In Shell, type:
git reset HEAD~
. - Keep hitting the statement as many times as you have commits.
- Voila.
Full Steps
First, ensure you have only the changes you do not want to commit. If I try commiting with .key
file, it will fail as it’s larger than 100 mb.
I want to commit the last two changes (something about this blog post), so I will commit it and push changes to the repository. Then, I will go the (machine-like icon) and click on “Shell…”.
Now, I will paste in the Terminal window the magic spell: git reset HEAD~
.
Some additional resources
-
https://rfortherestofus.com/2021/02/how-to-use-git-github-with-r/
-
https://happygitwithr.com/credential-caching.html#credential-caching
-
https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.