Skip to content

Commit 72c6f03

Browse files
done polishing local repo working section
1 parent 53e5639 commit 72c6f03

File tree

1 file changed

+75
-83
lines changed

1 file changed

+75
-83
lines changed

version-control.Rmd

Lines changed: 75 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ editing, and deleting files as you normally would—you must:
184184

185185
In this section we will discuss all three of these steps in detail.
186186

187-
### Commiting changes to a local repository
187+
### Committing changes to a local repository {#commit-changes}
188188

189189
When working on files in your local version control
190190
repository (e.g., using Jupyter) and saving your work, these changes will only initially exist in the
@@ -282,10 +282,10 @@ image_read("img/vc7-pull.png") %>%
282282
image_crop("3632x2000")
283283
```
284284

285-
## Working with remote repositories on GitHub
285+
## Working with remote repositories using GitHub
286286

287287
Now that you have been introduced to some of the key general concepts
288-
and workflows of Git version control, we will next walk through the practical steps.
288+
and workflows of Git version control, we will walk through the practical steps.
289289
There are several different ways to start using version control
290290
with a new project. For simplicity and ease of setup,
291291
we recommend creating a remote repository first.
@@ -350,16 +350,16 @@ image_read("img/version_control/new_repository_03.png") %>%
350350

351351
The pen tool can be used to edit existing plain text files. When you click on
352352
the pen tool the file will be opened in a text box where you can use your
353-
keyboard to make changes (Figure \@ref(fig:pen-tool-01) & \@ref(fig:pen-tool-02)).
353+
keyboard to make changes (Figures \@ref(fig:pen-tool-01) and \@ref(fig:pen-tool-02)).
354354

355-
```{r pen-tool-01, fig.cap = 'Clicking on the pen tool opens a textbox for editing plain text files.', fig.retina = 2}
355+
```{r pen-tool-01, fig.cap = 'Clicking on the pen tool opens a text box for editing plain text files.', fig.retina = 2}
356356
image_read("img/version_control/pen-tool_01.png") %>%
357357
image_flop() %>%
358358
image_crop("3584x1500") %>%
359359
image_flop()
360360
```
361361

362-
```{r pen-tool-02, fig.cap = 'The textbox where edits can be made after clicking on the pen tool.', fig.retina = 2}
362+
```{r pen-tool-02, fig.cap = 'The text box where edits can be made after clicking on the pen tool.', fig.retina = 2}
363363
image_read("img/version_control/pen-tool_02.png") %>%
364364
# image_flop() %>%
365365
image_crop("3584x1300") # %>%
@@ -374,6 +374,17 @@ generates a useful version history for that file. On GitHub, if you click the
374374
green "Commit changes" button, it will save the file and then make a commit
375375
(Figure \@ref(fig:pen-tool-03)).
376376

377+
Recall from Section \@ref(commit-changes) that you normally have to add files
378+
to the staging area before committing them. Why don't we have to do that when
379+
we work directly on GitHub? Behind the scenes, when you click the green "Commit changes"
380+
button, GitHub *is* adding that one file to the staging area prior to committing it.
381+
But note that on GitHub you are limited to committing changes to only one file at a time.
382+
When you work in your own local repository, you can commit
383+
changes to multiple files simultaneously. This is especially useful when one
384+
"improvement" to the project involves modifying multiple files.
385+
You can also do things like run code when working in a local repository, which you cannot
386+
do on GitHub. In general, editing on GitHub is reserved for small edits to plain text files.
387+
377388
```{r pen-tool-03, fig.cap = 'Saving changes using the pen tool requires committing those changes, and an associated commit message.', fig.retina = 2}
378389
image_read("img/version_control/pen-tool_03.png") %>%
379390
image_crop("3583x1500+1+500")
@@ -403,7 +414,7 @@ Note that GitHub understands and renders `.md` files using a
403414
very similar to Jupyter notebooks, so the "Preview" tab is especially helpful
404415
for checking markdown code correctness.
405416

406-
```{r create-new-file-02, fig.cap = 'New plain text files require a filename be inputted in the textbox circled in red, and file content entered in the larger text box (red arrow).', fig.retina = 2}
417+
```{r create-new-file-02, fig.cap = 'New plain text files require a filename in the text box circled in red, and file content entered in the larger text box (red arrow).', fig.retina = 2}
407418
image_read("img/version_control/create-new-file_02.png") %>%
408419
image_flop() %>%
409420
image_crop("3584x1300") %>%
@@ -421,6 +432,11 @@ image_read("img/version_control/create-new-file_03.png") %>%
421432
You can also upload files that you have created on your local machine by using
422433
the "Add file" drop down menu and selecting "Upload files"
423434
(Figure \@ref(fig:upload-files-01)).
435+
To select the files from your local computer to upload, you can either drag and
436+
drop them into the grey box area shown below, or click the "choose your files"
437+
link to access a file browser dialog. Once the files you want to upload have
438+
been selected, click the green "Commit changes" button at the bottom of the
439+
page (Figure \@ref(fig:upload-files-02)).
424440

425441
```{r upload-files-01, fig.cap = 'New files of any type can be uploaded to GitHub.', fig.retina = 2}
426442
image_read("img/version_control/upload-files_01.png") %>%
@@ -429,58 +445,48 @@ image_read("img/version_control/upload-files_01.png") %>%
429445
image_flop()
430446
```
431447

432-
To select the files from your local computer to upload, you can either drag and
433-
drop them into the grey box area shown below, or click the "choose your files"
434-
link to access a file browser dialog. Once the files you want to upload have
435-
been selected, click the green "Commit changes" button at the bottom of the
436-
page (Figure \@ref(fig:upload-files-02)).
437-
438-
```{r upload-files-02, fig.cap = 'Uploaded files can specified by dragging them into the GitHub website where specified (red circle) or by clicking on the "choose your files" to select them via a file browser. Uploaded files are also required to be committed along with an associated commit message.', fig.retina = 2}
448+
```{r upload-files-02, fig.cap = 'Specify files to upload by dragging them into the GitHub website (red circle) or by clicking on "choose your files." Uploaded files are also required to be committed along with an associated commit message.', fig.retina = 2}
439449
image_read("img/version_control/upload-files_02.png") %>%
440450
image_flop() %>%
441451
image_crop("3584x2200") %>%
442452
image_flop()
443453
```
444454

445455
Note that Git and GitHub are designed to track changes in individual files.
446-
*Do not* upload your whole project in an archive file (e.g. `.zip`). If you do,
447-
then Git can only keep track of changes to the entire `.zip` file---that
448-
wouldn't be very useful if you're trying to see the history of changes to a
449-
single code file in your project!
450-
456+
**Do not** upload your whole project in an archive file (e.g. `.zip`). If you do,
457+
then Git can only keep track of changes to the entire `.zip` file, which will not
458+
be human-readable. Committing one big archive defeats the whole purpose of using
459+
version control: you won't be able to see, interpret, or find changes in the history
460+
of any of the actual content of your project!
451461

452462
## Working with local repositories using Jupyter {#local-repo-jupyter}
453-
454-
### Cloning a repository using Jupyter
455-
456-
Although there are several ways to create and edit files on
457-
GitHub, they are not quite powerful enough for
458-
efficiently creating and editing complex files, or files that need to be
459-
executed to assess whether they work (e.g., files containing code).
460-
For example,
461-
you wouldn't be able to run analysis written with R code directly on GitHub.
462-
Thus, it is useful to be able to connect the project repository
463-
that was created on GitHub to a coding environment.
464-
This can be done using the Git.
465-
Git can be run via several different ways,
466-
below we show how to do this using the Jupyter Git extension.
467-
The Jupyter Git extension can be run via Jupyter on your local computer,
468-
or on a JupyterHub server.
463+
Although there are several ways to create and edit files on GitHub, they are
464+
not quite powerful enough for efficiently creating and editing complex files,
465+
or files that need to be executed to assess whether they work (e.g., files
466+
containing code). For example, you wouldn't be able to run analysis written
467+
with R code directly on GitHub. Thus, it is useful to be able to connect the
468+
remote repository that was created on GitHub to a local coding environment. This
469+
can be done by creating and working in a local copy of the repository.
470+
In this chapter, we focus on interacting with Git via Jupyter using
471+
the Jupyter Git extension. The Jupyter Git extension
472+
can be run via Jupyter on your local computer, or on a JupyterHub server.
469473
*Note: we recommend reading Chapter \@ref(getting-started-with-jupyter)*
470474
*to learn how to use Jupyter before reading this chapter.*
471475

472-
We need to *clone* our project's Git repository to our local computer
473-
or JupyterHub server---i.e., make a
476+
### Cloning a repository using Jupyter
477+
478+
The first step is to *clone* the remote repository on GitHub to create a local repository,
479+
i.e., make a
474480
copy that knows where it was obtained from so that it knows where send/receive
475481
new committed edits. In order to do this, first copy the URL from the HTTPS tab
476482
of the Code drop down menu on GitHub (Figure \@ref(fig:clone-02)).
477483

478-
```{r clone-02, fig.cap = 'The remote address (URL) corresponding to the location of the GitHub repository needed to clone it to a computer can be found under the green "Code" button.', fig.retina = 2}
484+
```{r clone-02, fig.cap = 'The remote address (URL) corresponding to the location of the remote GitHub repository can be found in the green "Code" drop down menu.', fig.retina = 2}
479485
image_read("img/version_control/clone_02.png") %>%
480486
image_crop("3584x1500")
481487
```
482488

483-
Then open JupyterHub, and click the Git+ icon on the file browser tab
489+
Then open Jupyter, and click the Git+ icon on the file browser tab
484490
(Figure \@ref(fig:clone-01)).
485491

486492
```{r clone-01, fig.cap = 'The Jupyter Git Clone icon (red circle)', fig.retina = 2}
@@ -496,56 +502,44 @@ image_read("img/version_control/clone_03.png") %>%
496502
image_crop("2400x1430+1")
497503
```
498504

499-
On the file browser tab, you will now see a folder for your project's repository
500-
(and inside it will be all the files that existed on GitHub,
501-
Figure \@ref(fig:clone-04)).
505+
On the file browser tab, you will now see a folder for the repository.
506+
Inside this folder will be all the files that existed on GitHub (Figure \@ref(fig:clone-04)).
502507

503508
```{r clone-04, fig.cap = 'Cloned GitHub repositories can been seen and accessed via the Jupyter file browser.', fig.retina = 2}
504509
image_read("img/version_control/clone_04.png") %>%
505510
image_crop("2400x1430+1")
506511
```
507512

508-
### Working in a cloned repository using Jupyter
509-
510-
Now that you have cloned your repository from GitHub to your local computer
511-
(i.e., JupyterHub or your laptop), you can get to work editing, creating,
512-
and deleting files using an application, such as Jupyter.
513-
Below we walk through how to use the Jupyter Git extension tool to do
514-
each of the steps outlined above.
515-
516513
### Specifying files to commit
517-
518-
Below we created and saved a new file (named `eda.ipynb`) that we would
519-
like to send back to the project repository on GitHub.
514+
Now that we have cloned the remote repository from GitHub to create a local repository,
515+
you can get to work editing, creating, and deleting files.
516+
For example, suppose we created and saved a new file (named `eda.ipynb`) that we would
517+
like to send back to the project repository on GitHub (Figure \@ref(fig:git-add-01)).
520518
To "add" this modified file to the staging area (i.e., flag that this is a
521-
file whose changes we would like to commit), we click the Jupyter Git extension
522-
icon on the far left-hand side of JupyterLab (Figure \@ref(fig:git-add-01)).
519+
file whose changes we would like to commit), click the Jupyter Git extension
520+
icon on the far left-hand side of Jupyter (Figure \@ref(fig:git-add-01)).
523521

524522
```{r git-add-01, fig.cap = 'Jupyter Git extension icon (circled in red).', fig.retina = 2}
525523
image_read("img/version_control/git_add_01.png")
526524
```
527525

528-
This opens the Jupyter Git graphical user interface pane, and then we
529-
click the plus sign (+) beside the file that we want to "add"
530-
(Figure \@ref(fig:git-add-02)).
526+
This opens the Jupyter Git graphical user interface pane. Next,
527+
click the plus sign (+) beside the file(s) that you want to "add"
528+
(Figure \@ref(fig:git-add-02)). Note that because this is the
529+
first change for this file, it falls under the "Untracked" heading.
530+
However, next time we edit this file and want to add the changes,
531+
we will find it under the "Changed" heading.
531532

532-
> **Note:** because this is the first change for this file that we want to add,
533-
> it falls under the "Untracked" heading.
534-
> However, next time we edit this file
535-
> and want to add the changes we made,
536-
> we will find it under the "Changed" heading.
537-
538-
> **Note:** do not add the `eda-checkpoint.ipynb` file
539-
> (sometimes called `.ipynb_checkpoints`).
540-
> This file is automatically created by Jupyter when you work on `eda.ipynb`.
541-
> You generally do not add auto-generated files to Git repositories,
542-
> only add the files you directly create and edit.
533+
You will also see an `eda-checkpoint.ipynb` file under the "Untracked" heading.
534+
This is a temporary "checkpoint file" created by Jupyter when you work on `eda.ipynb`.
535+
You generally do not want to add auto-generated files to Git repositories;
536+
only add the files you directly create and edit.
543537

544538
```{r git-add-02, fig.cap = 'The plus sign (+) is used to add the `eda.ipynb` file to the staging area.', fig.retina = 2}
545539
image_read("img/version_control/git_add_02.png")
546540
```
547541
548-
This moves the file from the "Untracked" heading to the "Staged" heading,
542+
Clicking the plus sign (+) moves the file from the "Untracked" heading to the "Staged" heading,
549543
flagging this file so that Git knows we want a snapshot of its current state
550544
as a commit (Figure \@ref(fig:git-add-02)).
551545
Now we are ready to "commit" the changes.
@@ -559,53 +553,51 @@ image_read("img/version_control/git_add_03.png")
559553
### Making the commit
560554

561555
To snapshot the changes with an associated commit message,
562-
we put the message in the text box at the bottom of the Git pane
556+
we put a message in the text box at the bottom of the Git pane
563557
and click on the blue "Commit" button (Figure \@ref(fig:git-commit-01)).
564558
It is highly recommended to write useful and meaningful messages about what
565559
was changed. These commit messages, and the datetime stamp for a given
566560
commit, are the primary means to navigate through the project's history in the
567561
event that we need to view or retrieve a past version of a file, or
568562
revert our project to an earlier state.
563+
When you click the "Commit" button for the first time, you will be prompted to
564+
enter your name and email. This only needs to be done once for each machine
565+
you use Git on.
569566

570567
```{r git-commit-01, fig.cap = 'A commit message must be added into the Jupyter Git extension commit text box before the blue Commit button can be used to record the commit.', fig.retina = 2}
571568
image_read("img/version_control/git_commit_01.png")
572569
```
573570

574-
> When you click the "Commit" button for the first time, you will be prompted to
575-
> enter your name and email. This only needs to be done once for each machine
576-
> you use Git on.
577-
578571
After "committing" the file(s), you will see there there are 0 "Staged" files
579-
and we are now ready to push our changes (and the attached commit message)
580-
to our project repository on GitHub (Figure \@ref(fig:git-commit-01)).
572+
and we are now ready to push our changes
573+
to our remote repository on GitHub (Figure \@ref(fig:git-commit-01)).
581574

582575
```{r git-commit-03, fig.cap = 'After recording a commit, the staging area should be empty.', fig.retina = 2}
583576
image_read("img/version_control/git_commit_03.png")
584577
```
585578

586579
### Pushing the commits to GitHub
587580

588-
To send the committed changes back to the project repository on
589-
GitHub, we need to *push* them.
590-
To do this we click on the cloud icon with the up arrow on the Jupyter Git tab
581+
To send the committed changes back to the remote repository on
582+
GitHub, we need to *push* them. To do this we click on the cloud icon with the up arrow on the Jupyter Git tab
591583
(Figure \@ref(fig:git-push-01)).
592584

593-
```{r git-push-01, fig.cap = 'The Jupyter Git extension push button (circled in red).', fig.retina = 2}
585+
```{r git-push-01, fig.cap = 'The Jupyter Git extension "push" button (circled in red).', fig.retina = 2}
594586
image_read("img/version_control/git_push_01.png")
595587
```
596588

597589
We will then be prompted to enter our GitHub username
598590
and password, and click the blue "OK" button (Figure \@ref(fig:git-push-02)).
599591

600-
```{r git-push-02, fig.cap = 'The Jupyter Git extension to enter Git credentials to authorize the push to the remote repository.', fig.retina = 2}
592+
```{r git-push-02, fig.cap = 'Enter your Git credentials to authorize the push to the remote repository.', fig.retina = 2}
601593
image_read("img/version_control/git_push_02.png")
602594
```
603595

604596
If the files were successfully pushed to our project repository on
605597
GitHub we will be given the success message shown below.
606598
Click "Dismiss" to continue working in Jupyter (Figure \@ref(fig:git-push-03)).
607599

608-
```{r git-push-03, fig.cap = 'The Jupyter Git extension prompt that the push was successful.', fig.retina = 2}
600+
```{r git-push-03, fig.cap = 'The prompt that the push was successful.', fig.retina = 2}
609601
image_read("img/version_control/git_push_03.png")
610602
```
611603

0 commit comments

Comments
 (0)