The hard part of using Git in RStudio is getting it set-up.
git.exe
resides.Go to the set-up instructions and scroll down to the section on how to set-up RStudio with Git. Follow instructions carefully and slowly.
Note. Creating the repo locally first often leads to misery in my experience. Often safer to start by making a blank repo on GitHub or GitLab.
Create a RStudio project (upper right with the blue cube with R). New project… > New Directory > New Project
Check the box that says Create a git repository
. You have made a local repository.
Add a file. File > New File > R Script
Type something and then save the file.
Click the Git
tab in the upper right.
Click the changes that you want to commit (do all). And click Commit
. Add a comment: first line is subject, newline, description (options).
Repeat 4-6 a few times.
Now look at the history. The little clock-like icon (or History in the Git window).
filter by file
to see just the changes to one file.View file @...
…or push an existing repository from the command line
git remote add origin https://github.com/<youraccount>/<reponame>.git
git push -u origin master
If you want to copy someone’s repository on GitHub or make a copy of one of your own, there are a few approaches that you can take. I am going to use https://github.com/RVerse-Tutorials/Test
as the repository that you want to copy and we will put the repository at Documents/GitHub/Test
.
https://github.com/RVerse-Tutorials/Test
on GitHub and click the ‘fork’ button in the upper right. Follow the instructions.Now you need to get it on your computer.
https://github.com/<your github account>/Test
and leave the “Project Directory Name” empty. And then choose a directory in which to put the new repository and click OK.If you are using GitHub Desktop, you need to add it to that too.
~/Documents/GitHub/Test
and add.The problem with forking is that you can’t fork your own repositories and if you fork someone else’s repository, your fork will always show theirs as a ‘parent’—which doesn’t really have a bad effect but I rarely want my copy of someone’s repo to be linked to theirs in any way. Normally forking is used when you are contributing to the parent repository and need a copy to work on.
This method is pretty failsafe and I find easy to remember. This how I normally copy one of my own folders and make a new GitHub repo. I don’t use Git at the command line very often and rather than looking up how to do it, getting something wrong 3x and then researching how to debug the problem, and then finding I’ve spent the morning with a simple task…. I just do the following now.
Test
) on GitHub and click the button to add a Readme.md file.https://github.com/RVerse-Tutorials/Test
and leave the “Project Directory Name” empty. And then choose a directory in which to put it and click OK.This method will have your new repository associated with the repository from where you downloaded. If it is not your own GitHub repository, you don’t want this because you will not be able to push changes to GitHub.
git remote rm origin
This detaches the cloned repository from the remote repository on GitHub from where you cloned it.
Add the new repository to GitHub Desktop and then publish to GitHub. From GitHub Desktop, go to File>Add Local Repository and then navigate to ~/Documents/GitHub/Test
and add.
Publish to GitHub. Once you do step 3, a ‘Publish to GitHub’ button will appear. Click that to publish to GitHub.
Note, there are Git commands you could use to do steps 3 and 4, but in this workshop we are using GitHub Desktop.
Another way is to download the repository as a zip file and unzip. Watch a video that shows you how to do this
Go to https://github.com/RVerse-Tutorials/Test and click ‘Clone or download’ and chose ‘Download Zip’. Unzip and you’ll probably want to remove ‘master’ added to the end of the repository name.
If you chose, ‘Clone in Desktop’, you’ll need to open a terminal window, navigate to the new folder you just downloaded, and run the git code git remote rm origin
from within the terminal to detach the repository from the RVerse-Tutorials GitHub account.
We will not be doing this in this short course, but often you will want to install packages with C++ code. To do that, you will need Rtools (Windows) or Xcode (Mac)