1.5 Starting from scratch
Open the slides in a new tab here.
Exercises
Create a new project either from File > New Project or using the drop-down menu in the upper-right corner of RStudio. This time, choose “New Directory” and then “New Project”.
Choose a name for your new project and where to store it. Check “Create a git repository.” You can leave “Use renv with this project” unchecked (for now!).
Look at the git pane. What do you notice compared to the first time we looked at this pane? Stage and commit the files (I usually use “initial commit” as my first commit message since I haven’t don’t anything yet!). You’ll notice the “Push” button is grayed out – we’ll have to fix that!
Open up your web browser to GitHub. There are a few different ways to make a new repository; click one of them.
Choose a name (preferably one that matches the name you gave your R project). You can also add a description and choose to make it private, if you wish. (If private, you’ll have to invite the teaching team as collaborators so we can grade it!) You don’t need to click anything else.
GitHub is going to give you some options for code. You’re going to use the second option: “push an existing repository from the command line” because you’ve already initialized the repo in RStudio. You are going to run this code in the terminal. You’ll find that in a tab next to the console.
Even though it looks like you can copy and paste the 3 lines of code at once, you can’t! You’ll get the error you see above (I do this every time). Instead, copy and paste and run them one at a time. Then refresh your GitHub page!
Create a new file called
secrets.txt
(you can do this via File > New File > Text file, then save the file). Write down your deepest, darkest secrets in there.Uh oh! It shows up in the git pane. You don’t want to accidentally commit this to your repo!
Open
.gitignore
via the RStudio filepane.1 Add “secrets.txt” below the files that RStudio helpfully ignored for you. Then save. What happened in the git pane?Whenever you have something that shouldn’t be shared with the world, like a password or a dataset, you should add it to the
.gitignore
. There are a lot of examples here of how you can match folders and file patterns.Set up your folders how you’d like in your repo. For example, along with an
R
folder and adata
folder, I like to have adocuments
folder. Find some data online, download it, and store it in yourdata
folder. Commit and push to GitHub!Some fun options for data are:
Resources
- This is a slightly simpler (I think) version of the Existing project, GitHub last workflow
- .gitignore patterns
- .gitignore documentation