-
Notifications
You must be signed in to change notification settings - Fork 336
/
usage-existing-project-github-first.Rmd
97 lines (73 loc) · 3.64 KB
/
usage-existing-project-github-first.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Existing project, GitHub first {#existing-github-first}
This is a novice-friendly workflow for bringing an existing R project into the RStudio and Git/GitHub universe.
We do this in a slightly goofy way, in order to avoid using Git at the command line.
You won't want to work this way forever, but it's perfectly fine as you're getting started!
At first, the main goal is to accumulate some experience and momentum.
There is nothing goofy about the GitHub repo that this creates, it is completely standard.
Transition to a more elegant process when you're ready.
We assume you've got your existing R project isolated in a directory on your computer.
If that's not already true, make it so.
Create a directory and marshal all the existing data and R scripts there.
It doesn't really matter where you do this, but note where the project currently lives.
## Make a repo on GitHub
```{r echo = FALSE, results = "asis"}
dat <- list(
repository_name_text = glue::glue("
`myrepo` or a similarly short name for this existing project. Approach \\
this similar to a variable name, in code: descriptive but brief, no \\
whitespace. Letters, digits, `-`, `.`, or `_` are allowed."),
description_text = glue::glue("
\"Analysis of the stuff\" or any short description of the project. Write \\
this for humans."),
initialize_text = "Initialize this repository with: Add a README file."
)
insert <- glue::glue_data(
dat,
readr::read_file("child-create-a-github-repo.Rmd"),
.open = "<<<", .close = ">>>"
)
res <- knitr::knit_child(text = insert, quiet = TRUE)
cat(res, sep = '\n')
```
## New RStudio Project via git clone {#git-clone-usethis-rstudio}
```{r echo = FALSE, results = "asis"}
insert <- readr::read_file("child-clone-a-github-repo.Rmd")
res <- knitr::knit_child(text = insert, quiet = TRUE)
cat(res, sep = '\n')
```
## Bring your existing project over
Using your favorite method of moving or copying files, copy the files that constitute your existing project into the directory for this new project.
In RStudio, consult the Git pane and the file browser.
* Are you seeing all the files? They should be here if your move/copy was successful.
* Are they showing up in the Git pane with questions marks? They should be appearing as new untracked files.
## Stage and commit
Commit your files to this repo. How?
* Click the "Git" tab in upper right pane
* Check the "Staged" box for all files that you want to commit.
- Default: stage it.
- When to reconsider: this will all go to GitHub. Consider if that is
appropriate for each file. **You can absolutely keep a file locally,
without committing it to the Git repo and sending to GitHub**. Just let it
sit there in your Git pane, without being staged. No harm will be done. If
this is a long-term situation, list the file in `.gitignore`.
* If you're not already in the Git pop-up, click "Commit"
* Type a message in "Commit message", such as "Init project XYZ".
* Click "Commit"
## Push your local changes to GitHub
Click the green "Push" button to send your local changes to GitHub.
RStudio will display something like:
```console
>>> /usr/bin/git push origin HEAD:refs/heads/main
To https://github.com/jennybc/myrepo.git
3a2171f..6d58539 HEAD -> main
```
## Confirm the local change propagated to the GitHub remote
Go back to the browser.
I assume we're still viewing your new GitHub repo.
Refresh.
You should see all the project files you committed there.
If you click on "commits," you should see one with the message you used, e.g. "Init project XYZ".
## The end
```{r echo = FALSE, results = "asis"}
cat(readLines("child-the-end-of-repo-setup.Rmd"), sep = '\n')
```