DEV Community

Cover image for How to push your project to GitHub from RStudio
KaraniWachira
KaraniWachira

Posted on

How to push your project to GitHub from RStudio

In this article, I write about a step-by-step walk through I had the opportunity to guide members of DeKUT {R} Community, a student led data science community in Dedan Kimathi University in Kenya during our semester weekly meetups.

To begin with, you have to install R from the Comprehensive R Archive Network CRAN https://cran.r-project.org/

Image description
Type R --version on the terminal to view the version of R you have installed.

Secondly install RStudio IDE which is the best coding environment for R built by Posit https://posit.co/downloads/

Image description

RStudio IDE Screenshot

Another requirement is Git.
Git is a version control system which we will use to track changes to our project code.You can download from the appropriate version for your operating from https://git-scm.com/

Image description

Check Git version already installed

git --version
Enter fullscreen mode Exit fullscreen mode

To install Git on Ubuntu/Debian

sudo apt install git
Enter fullscreen mode Exit fullscreen mode

The last requirement you need is to create a github account, where we will create a repository to host out project source code. Navigate to https://github.com/ and signup

Image description

Creating a repository on GitHub

A repository is a "container" which holds all your projects files and each file revision history.

Image description

Give your repository an appropriate name and a brief description then, create repository.

Image description

Bravo! You have created a repository on GitHub.

Image description

Setting up your project on RStudio

Create a new project from and select the Version Control option on the new project wizard

Image description

Select version control

In the new project wizard select GIT as your version control to use

Image description

Remember the repository we created on GitHub, it time to use the repo's URL.

Image description

Copy the repository url and paste it on the Repository URL text box as shown below and click Create Project.

Image description

Load your project

For this article, I conducted exploratory data analysis and data visualization on the Titanic data in a markdown file.

To stage my file ready for commit, navigate to the Git Tab in the Environmental pane of the IDE.

Image description

Check the files you wish to stage for commit and click 'commit'.

The RStudio commit changes window will pop up, where you can view the project files and add a commit message as shown below.

Image description

Add a suitable commit message and commit your staged files.

Image description

At this point you have completed a commit of your files and they are ready to be pushed to GitHub.

Close the Git Commit window and click the green Push arrow above the commit message text box.

Image description

You will be prompted to provide your GitHub user name

Image description

Provide your generated GitHub access Token as your password and click OK.

Image description

Learn how to get your personal access token https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

DONE!

You have successfully pushed code from RStudio to GitHub

Image description

You can verify this by switching back to your github account on your browser and navigate to your project repository in my case Jaribio.

Image description

The repository link to visualizing Titanic is available here
https://github.com/KaraniWachira/Jaribio

Thank you for reading!

DeKUT {R} Community
Twitter: https://twitter.com/RDekut

Top comments (0)