How to use GitHub with RStudio

A tutorial for beginners

Pang Arissara
5 min readFeb 28, 2021

Github is a popular cloud-based service where users can create projects and share them with others, store code, updating code, and so on. For beginners who already known Rstudio and want to start using Github may be confusing and don’t know how to start. So, this article will guide you on how to use GitHub with RStudio. Let’s get started together!

Firstly, go to the GitHub website and click “sign in” to log in to Github if you already have a Github account, if you do not have please click “sign up” at the top right corner to create your account.

Homepage of the GitHub website
The log in page

The basic tasks on GitHub that you should know includes:

  1. Fork a repository: copying a repository to your account allowing you to make any changes without affecting the original project.
  2. Create a repository: creating a place where the project live in
  3. Create a branch: creating an isolated workplace allowing you to develop or experiment freely and safely without affecting the main part of a repository
  4. Add a new file: adding a new file to a repository
  5. Commit the changes: adding a commit message when any changes occur
  6. Push local file to a remote repository: pushing files in your computer to a remote repository liked with RStudio
  7. Create a pull request: allowing the selected branch to merge with the main branch

Fork a repository

  • Go to a repository containing the project that you interested in or want to make changes with your own idea.
  • Click “Fork” at the top right corner and select the place where you want to fork to.
Click “Fork” at the top-right corner
Choose where the project should fork to
Forking a repository is finished

Create a branch

  • Go to a forked repository or a repository that you already created.
  • Click the drop-down at “master” which is a default branch in a repository to create a branch from a default branch.
  • Click “Create branch” to finish creating a branch
Enter a branch name and click “Create branch”
Creating a branch named test is done

Add a new file and commit the change

  • Go to a repository that you want to add a new file
  • Click the drop-down at “Add file” and then click “Upload files”
  • Drag your file to the box or choose your file from your computer
  • Add commit changes to note what are you going to do
  • Click “Commit Changes” to save the commit
Click “Add file” and then click “Upload files”
Drag your file to the box or choose your file from your computer
Add commit changes and Click “Commit Changes” to save the commit

Push local files to a remote repository

ฺBefore you push local files to a remote repository, you have to clone a repository on GitHub to RStudio on your computer.

  • Go to a repository on GitHub that you want to push local files to
  • Click the drop-down at “Code” and click the clipart to copy the link
Click the drop-down at “Code” and click the clipart to copy the link
  • Open RStudio and go to “File” on the toolbar and select “ New project” to create a new project
  • Choose “Vision Control” and “Git” respectively
  • Paste the link in the blank of Repository URL and click “Create Project”
Choose “Vision Control”
Choose “Git”
Paste the link in the blank of Repository URL and click “Create Project”
  • Go to the Environment quadrant and choose “Git”
  • Click “Commit” and a new window is opened
Click “Commit”
  • Check out files that you want to push and click “Staged” in front of selected files
  • Add commit message and click “Commit”
  • Click “Push” to push local files to a remote repository
Click “Staged” in front of the selected file
Click “Commit” and then click “Push” to push a local file to a remote repository

Create a pull request

  • Go to the Environment quadrant and choose “Git”
  • Change a branch from the main to another branch that you want to create a pull request
  • Push selected files to a remote repository as already described above
Change a branch from the main to another branch and click “Commit” to further push selected files

After local files are already pushed to a repository:

  • Go to a repository liked with RStudio and click “ Compare & pull request”
  • Click “Create pull request”
  • Click “Merge pull request” and “Confirm merge” respectively
Click “ Compare & pull request”
Click “Create pull request”
Click “Merge pull request”
Click “Confirm merge”
The selected branch is already merged with the main branch

That’s all the tutorials for using GitHub with RStudio. I hope beginners who get started using Github can follow this tutorial :)

Arissara

--

--