Skip to content

Commit 08a5ef8

Browse files
authored
Merge pull request #5 from lter/dev_generalizing-ide
Adding instructions for Positron & expanding instructions for RStudio
2 parents 3a6af21 + 1326776 commit 08a5ef8

186 files changed

Lines changed: 888 additions & 565 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This reflects the current state of the repository. Changes from the preceding ve
55
- Added Zenodo DOI and full workshop citation to README and homepage of workshop
66
- Clarified GitHub 'by itself' versus 'with an IDE' and made minor edits to both original topics in service of making this distinction clear
77
- Tweaked sidebar to make a new 'background' section to house the workflows module and some of the Git-specific background that previously was the start of what is now called the 'GitHub by itself' module
8+
- Overhauled all IDE-related tutorials to use new, more clear images and explanatory text for both RStudio and Positron
89

910
## Version 1.3
1011

_freeze/index/execute-results/html.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

_freeze/prep-steps/connect_git-github/execute-results/html.json renamed to _freeze/prep-steps/connect_git-github_rstudio/execute-results/html.json

File renamed without changes.

_freeze/prep-steps/install_r/execute-results/html.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

_quarto.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ website:
2828
- section: "Using GitHub..."
2929
contents:
3030
- text: "With a Browser"
31-
href: github.qmd
31+
href: browser.qmd
3232
- text: "With an IDE"
33-
href: rstudio.qmd
33+
href: ide.qmd
3434
- section: "Advanced Topics"
3535
contents:
3636
- conflicts.qmd
3737
- branches.qmd
3838
- forks.qmd
39-
- git_ignore.qmd
39+
- git-ignore.qmd
4040
- section: "Project Management"
4141
contents:
4242
- issues.qmd

branches.qmd

Lines changed: 150 additions & 51 deletions
Large diffs are not rendered by default.

github.qmd renamed to browser.qmd

Lines changed: 39 additions & 31 deletions
Large diffs are not rendered by default.

conflicts.qmd

Lines changed: 63 additions & 60 deletions
Large diffs are not rendered by default.

forks.qmd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ In the top right of the repository's GitHub page there is a "Fork" button (betwe
5858
<img src="images/forks/forks-1-start.png" alt="Screenshot of the top of a GitHub repository including the 'fork' button in the top right (in-line with the name of the repository)" width="100%" />
5959
</p>
6060

61-
This redirects you to a page that is very similar to the page for creating a new repository *de novo* (see Chapter 3: Using GitHub).
61+
This redirects you to a page that is very similar to the page for creating a new repository _de novo_.
6262

63-
Here you can select who you want to own the repository from a dropdown including any organizations you are a member of and your username if you want to personally own the fork.
64-
65-
You can also change the repository name (though the default is to retain the same name) and add a description of your purpose for the fork.
63+
Here you can select who you want to own the repository from a dropdown including any organizations you are a member of and your username if you want to personally own the fork. You can also change the repository name (though the default is to retain the same name) and add a description of your purpose for the fork.
6664

6765
You may notice that in this page you do not have the option to specify public versus private or any of the 'initialize' steps (e.g., README, gitignore, or licence). Forks will inherit these settings from the repository they are forked from so they do not need to specified here.
6866

git-ignore.qmd

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
---
2+
title: "The .gitignore"
3+
---
4+
5+
## Module Learning Objectives
6+
7+
By the end of this module, you will be able to:
8+
9+
- <u>Create</u> a ".gitignore" in a repository using a GitHub template
10+
- <u>Explain</u> the purpose of a ".gitignore" in collaborative projects
11+
- <u>Evaluate</u> the content you think might warrant adding to the ".gitignore"
12+
13+
## Overview
14+
15+
A ".gitignore" is a file you can use to tell Git what _not_ to track. **Any file/folder whose name is in the ".gitignore" will not be tracked by Git.** This is useful if you want to include data in your local version of your repository but don't want to risk sharing that data by committing it to a public GitHub repository. This file exists at the top level of every repository and can be customized however is most useful to you and your collaborators.
16+
17+
## Creating a ".gitignore"
18+
19+
When you first create a repository you will have the opportunity to select a template ".gitignore" based on the coding language you plan on using. During the process of creating a repository, you can choose one of the templates curated by GitHub for a variety of coding languages. These templates exclude some typical machine-readable files that--while necessary for standard IDEs/background tasks--are not meaningful to track with version control.
20+
21+
To add a ".gitignore" during the repository creation phase, simply **click the dropdown menu and start typing the name of your coding language.** Unfortunately for R users, typing just "R" returns all templates that _contain_ the letter 'r' so you will need to scroll a bit to find the option that is actually for the R language. **Once you find the template you want, click it** and the template dropdown should change from ".gitignore template: None" to ".gitignore template: \<your pick\>".
22+
23+
<p align="center">
24+
<img src="images/browser/new-repo-02_repo-details-1.png" alt="Screenshot of the page on GitHub that appears when you click 'new repository'. Contains empty dialogue fields for the repository name and description as well as options for public versus private repositories among other initialization options" width="60%"/>
25+
<img src="images/browser/new-repo-02b_repo-details-2.png" alt="Screenshot of the page on GitHub that appears when you click 'new repository'. Contains empty dialogue fields for the repository name and description as well as options for public versus private repositories among other initialization options" width="60%"/>
26+
</p>
27+
28+
If you create a repository without choosing a ".gitignore" template, don't worry: you can always create one later! If you want to create a ".gitignore" in an extant repository that lacks one, run the relevant command line code for your computer's operating system in your IDE's {{<fa terminal >}} "Terminal" pane.
29+
30+
:::{.panel-tabset}
31+
#### {{< fa brands apple >}} Mac / {{< fa brands linux >}} Linux
32+
33+
```
34+
touch .gitignore
35+
```
36+
37+
#### {{< fa brands windows >}} Windows
38+
39+
```
40+
copy NUL .gitignore
41+
```
42+
43+
If `copy NUL` does not work, try `touch` instead.
44+
45+
:::
46+
47+
## Using a ".gitignore"
48+
49+
A classic use-case for a ".gitignore"--as previously mentioned--is to ignore any data files that you have in your working directory but that you don't want Git to track of GitHub to store. In general, **script inputs and outputs _should not_ be tracked by Git or put in GitHub.** Versioning of tabular data doesn't really work very well and it'll clutter your GitHub repository with data files that you already have access to elsewhere.
50+
51+
Additionally, storing script inputs/outputs both on GitHub and elsewhere (e.g., Google Drive, Dropbox) undermines the "single source of truth" and dramatically increases the risk that you accidentally work with a superseded input file and get incorrect results.
52+
53+
Taken together, **the following demonstration of how to use a ".gitignore" will focus on ignoring a new data file in the working directory.** This file is informatively named "data.csv".
54+
55+
::::{.panel-tabset}
56+
### In RStudio
57+
58+
To begin, we can **check the Git pane of RStudio to confirm that Git does see "data.csv"** even though Git is not tracking it currently.
59+
60+
<p align="center">
61+
<img src="images/ignore/rstudio-01_untracked-csv.png" alt="Screen capture of RStudio where the Git pane shows an untracked file named 'data.csv'" width="100%"/>
62+
</p>
63+
64+
With that confirmed, **click over to the "Files" pane.** Because the ".gitignore" file starts with a period, it is likely invisible to your standard file explorer program but RStudio's "Files" pane does see it and easily lets you interact with it.
65+
66+
<p align="center">
67+
<img src="images/ignore/rstudio-02_files.png" alt="Screen capture of RStudio with the 'Files' pane open" width="100%"/>
68+
</p>
69+
70+
In the "Files" pane, **click the ".gitignore" to open it**. If you scroll through you can see that the template from GitHub includes a number of files, many of which you may never have seen (again, often because they start with a period and are thus not easily visible).
71+
72+
<p align="center">
73+
<img src="images/ignore/rstudio-03_ignore-open.png" alt="Screen capture of RStudio with the R template '.gitignore' from GitHub open" width="100%"/>
74+
</p>
75+
76+
While currently we only have "data.csv" in our working directory, we can safely assume that we don't want _any_ CSVs to be tracked by Git. So, rather than entering "data.csv" into the ".gitignore", let's **add a wildcard for _all_ CSVs by entering "\*.csv" at the bottom of the ".gitignore".** Note that in the below screen shot, we haven't saved our edits to the ".gitignore" so the "Git" pane still (1) shows "data.csv" and (2) _does not_ show any modifications to the ".gitignore".
77+
78+
:::{.callout-note}
79+
#### Comments in the ".gitignore"
80+
81+
You can enter comments in the ".gitignore" in the same way you would in R/Python code: by adding a `#` to the start of the line. This can be helpful if you want to add small documentation of what is being ignored or why it is being ignored.
82+
:::
83+
84+
<p align="center">
85+
<img src="images/ignore/rstudio-04_ignore-unsaved.png" alt="Screen capture of RStudio with the R template '.gitignore' from GitHub open and edited but with unsaved changes" width="100%"/>
86+
</p>
87+
88+
Once you **save the edits to the ".gitignore"**, you'll notice that the Git pane automatically updates to (1) no longer show "data.csv" and (2) show that the ".gitignore" has been modified since the last commit. You can then **commit and push your edits to the ".gitignore" in the same way you would edits to any other file.**
89+
90+
<p align="center">
91+
<img src="images/ignore/rstudio-05_ignore-saved.png" alt="Screen capture of RStudio where the Git pane shows un-committed edits to the '.gitignore'" width="100%"/>
92+
</p>
93+
94+
### In Positron
95+
96+
To begin, we can **check the "source control" pane of Positron to confirm that Git does see "data.csv"** even though Git is not tracking it currently.
97+
98+
<p align="center">
99+
<img src="images/ignore/positron-01_untracked-csv.png" alt="Screen capture of Positron where the source control pane shows an untracked file named 'data.csv'" width="50%"/>
100+
</p>
101+
102+
With that confirmed, **click over to the "Explorer" pane.** Because the ".gitignore" file starts with a period, it is likely invisible to your standard file explorer program but Positron's "Explorer" pane does see it and easily lets you interact with it.
103+
104+
<p align="center">
105+
<img src="images/ignore/positron-02_files.png" alt="Screen capture of Positron with the 'Explorer' pane open" width="50%"/>
106+
</p>
107+
108+
In the "Explorer" pane, **click the ".gitignore" to open it**. If you scroll through you can see that the template from GitHub includes a number of files, many of which you may never have seen (again, often because they start with a period and are thus not easily visible).
109+
110+
<p align="center">
111+
<img src="images/ignore/positron-03_ignore-open.png" alt="Screen capture of Positron with the R template '.gitignore' from GitHub open" width="50%"/>
112+
</p>
113+
114+
While currently we only have "data.csv" in our working directory, we can safely assume that we don't want _any_ CSVs to be tracked by Git. So, rather than entering "data.csv" into the ".gitignore", let's **add a wildcard for _all_ CSVs by entering "\*.csv" at the bottom of the ".gitignore".** Note that in the below screen shot, we haven't saved our edits to the ".gitignore" so the "source control" pane still (1) shows "data.csv" and (2) _does not_ show any modifications to the ".gitignore".
115+
116+
:::{.callout-note}
117+
#### Comments in the ".gitignore"
118+
119+
You can enter comments in the ".gitignore" in the same way you would in R/Python code: by adding a `#` to the start of the line. This can be helpful if you want to add small documentation of what is being ignored or why it is being ignored.
120+
:::
121+
122+
<p align="center">
123+
<img src="images/ignore/positron-04_ignore-unsaved.png" alt="Screen capture of Positron with the R template '.gitignore' from GitHub open and edited but with unsaved changes" width="50%"/>
124+
</p>
125+
126+
Once you **save the edits to the ".gitignore"**, you'll notice that the source control pane automatically updates to (1) no longer show "data.csv" and (2) show that the ".gitignore" has been modified since the last commit. You can then **commit and push your edits to the ".gitignore" in the same way you would edits to any other file.**
127+
128+
<p align="center">
129+
<img src="images/ignore/positron-05_ignore-saved.png" alt="Screen capture of Positron where the Git pane shows un-committed edits to the '.gitignore'" width="50%"/>
130+
</p>
131+
132+
::::
133+
134+
## Ignoring Previously Tracked Content
135+
136+
Imagine a situation where you commit a file that you don't want Git to track and push that commit before realizing your mistake. Now that file is tracked by Git and every time you alter that file, it will show up in your IDE's version control pane. If you add the file to your ".gitignore" now, you won't be able to delete it because Git will stop tracking new changes (even deletions).
137+
138+
To resolve this, do the following:
139+
140+
1. Delete the offending file(s)
141+
- If you don't want to actually delete them, just move the file(s) out of the folder tracked by Git and move them back after step 3
142+
2. Commit the deletion
143+
3. Add the file(s) to the ".gitignore"
144+
4. Commit the change to the ".gitignore"
145+
5. **<span style="color:green">push</span>/sync** your changes with GitHub
146+
147+
## LTER SciComp Recommendations
148+
149+
There are many different opinions on what should go into a ".gitignore" but see below for some recommendations of things to ignore from the makers of this workshop. Feel free to disregard any that you don't feel apply to your needs.
150+
151+
### Start with the GitHub Template
152+
153+
**When you create a repository, use GitHub to add the template ".gitignore" for your chosen programming language.** There are a lot of small files that typical users don't care about that your project will accumulate over its lifecycle. If you don't flag these in the ".gitignore" it can become difficult to sort through your repository.
154+
155+
### Ignore Script Inputs and Outputs
156+
157+
**Version control is only meant to track code files so everything else should be ignored.** You should store your inputs somewhere that your collaborators can access them and--at the end of your project--archive them in a FAIR (<u>F</u>indable, <u>A</u>ccessible, <u>I</u>nteroperable, and <u>R</u>eusable) repository. Anyone wanting access to script outputs should be able to use those inputs to run the code themselves and generate them. Alternately, you may also want to upload script outputs to some static platform (e.g., Google Drive, Dropbox) so non-coders can easily access them there. In either case, **Git should not be used to track/store anything other than code files.**
158+
159+
One way of doing this fairly efficiently is to create dedicated folders for storing inputs or outputs (e.g., "data/", "graphs/", "results/") and then add those folder names to the ".gitignore". You could also ignore certain file types--as demonstrated above--if your inputs/outputs belong to a relatively small set of file types.
160+
161+
### Ignore the ".DS_Store" File
162+
163+
**If you are a {{< fa brands apple >}} Mac user, you should ignore the ".DS_Store" file.** Macs create a "Desktop Services Store" file (or ".DS_Store" for short) every time you open a folder. This file is invisible in your file manager but _can_ be committed. This file has no practical value in your project and a separate one exists in every subfolder so tracking them can quickly clutter a repository if you use subfolders.
164+
165+
### Ignore the R Project File
166+
167+
**If you are an RStudio user, you should ignore the ".Rproj" file.** This opinion is a relatively contentious one as RStudio users are deeply divided on whether to ignore this file or commit it. We recommend ignoring it for two reasons:
168+
169+
1. **If you commit your .Rproj file and someone later deletes it, the next time you pull, <u>Git will delete your .Rproj file</u> and cause RStudio to unexpectedly quit**--costing you all of your uncommitted edits. You will then need to create a new .Rproj in the desired folder and re-connect it to Git/GitHub.
170+
2. **All group members may have different names for their .Rproj files which means you could have as many of these files in your GitHub repository as there are collaborators.** This is cumbersome to sort through and attempts to fix this _post hoc_ run the risk outlined in the first point.
171+
172+
If these risks are not sufficient to sway you, consider that the .Rproj file serves almost no purpose in the first place. In theory, the .Rproj file can be used to define some RStudio settings for anyone who uses that .Rproj but few R users actually use it for this purpose and instead mostly use it as a shortcut to open the relevant project in RStudio.
173+
174+
Ultimately, this is up to you and your team to decide! Hopefully the rationale we provided above helps inform this decision and we are happy to discuss this more if you have follow up questions.

0 commit comments

Comments
 (0)