How to use GitHub with RStudio
A tutorial for beginners
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.
The basic tasks on GitHub that you should know includes:
- Fork a repository: copying a repository to your account allowing you to make any changes without affecting the original project.
- Create a repository: creating a place where the project live in
- Create a branch: creating an isolated workplace allowing you to develop or experiment freely and safely without affecting the main part of a repository
- Add a new file: adding a new file to a repository
- Commit the changes: adding a commit message when any changes occur
- Push local file to a remote repository: pushing files in your computer to a remote repository liked with RStudio
- 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.
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
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
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
- 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”
- Go to the Environment quadrant and choose “Git”
- Click “Commit” and a new window is opened
- 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
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
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
That’s all the tutorials for using GitHub with RStudio. I hope beginners who get started using Github can follow this tutorial :)
Arissara