Skip to content

Commit 0d19646

Browse files
edited version control PAT
1 parent d644968 commit 0d19646

File tree

1 file changed

+54
-51
lines changed

1 file changed

+54
-51
lines changed

version-control.Rmd

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -484,37 +484,39 @@ can be run by Jupyter on your local computer, or on a JupyterHub server.
484484

485485
### Generating a GitHub personal access token
486486

487-
To send and retrieve work between your local computer
488-
and the remote version control repository on GitHub,
489-
you will frequently need to perform authentication
490-
to prove you have the permission to do this.
487+
To send and retrieve work between your local repository
488+
and the remote repository on GitHub,
489+
you will frequently need to authenticate with GitHub
490+
to prove you have the required permission.
491491
There are several methods to do this,
492492
but for beginners we recommend using the HTTPS method
493-
because it is easier to do and requires less setup.
493+
because it is easier and requires less setup.
494494
In order to use the HTTPS method,
495-
GitHub requires the use of a personal access token
496-
(PAT)\index{git!personal access token}
497-
in place of a password because it is more secure.
495+
GitHub requires you to provide a *personal access token*. \index{GitHub!personal access token}
496+
A personal access token is like a password—so keep it a secret!—but it gives
497+
you more fine-grained control over what parts of your account
498+
the token can be used to access, and lets you set an expiry date for the authentication.
498499
To generate a personal access token,
499-
go to the Personal access tokens section of the Developer Settings page
500-
(accessed via the Settings menu).
501-
This is accessible via:
502-
[https://github.com/settings/tokens](https://github.com/settings/tokens).
500+
you must first visit [https://github.com/settings/tokens](https://github.com/settings/tokens),
501+
which will take you to the "Personal access tokens" page in your account settings.
503502
Once there, click "Generate new token" (Figure \@ref(fig:generate-pat-01)).
504503
Note that you may be asked to re-authenticate with your username
505504
and password to proceed.
506505

507-
(ref:generate-pat-01) The "Generate new token" button used to initiate the creation of a new personal access token. It is found on the Personal access tokens section of the Developer Settings page (accessed via the Settings menu).
506+
(ref:generate-pat-01) The "Generate new token" button used to initiate the creation of a new personal access token. It is found in the "Personal access tokens" section of the "Developer settings" page in your account settings.
508507

509508
```{r generate-pat-01, fig.cap = '(ref:generate-pat-01)', fig.retina = 2, out.width="100%"}
510509
image_read("img/generate-pat_01.png")
511510
```
512511

513-
Next you will be asked to add a note for your personal access token
514-
(this should be a descriptor of what you are using it for)
515-
and then select the scope of permission given to the token.
516-
We recommend selecting only the "repo" to err on the side of higher security.
517-
To generate the token, scroll to the bottom of that page
512+
Next you will be asked to add a note for your personal access token.
513+
This should be a descriptor of the token's purpose.
514+
Finally, you need to select permissions for the token; this is where
515+
you can control what parts of your account the token can be used to access.
516+
Make sure to choose only those permissions that you absolutely require. In
517+
Figure \@ref(fig:generate-pat-02), we tick only the "repo" box, which gives the
518+
token access to our repositories (so that we can push and pull) but none of our other GitHub
519+
account features. Finally, to generate the token, scroll to the bottom of that page
518520
and click the green "Generate token" button (Figure \@ref(fig:generate-pat-02)).
519521

520522
(ref:generate-pat-02) Webpage for creating a new personal access token.
@@ -524,24 +526,23 @@ image_read("img/generate-pat_02.png")
524526
```
525527

526528
Finally, you will be taken to a page where you will be able to see
527-
and copy the personal access token you just generated.
528-
You will only be able to see this once,
529-
so make sure you store this in a safe place
530-
that just you can access when you need to use it in the future
531-
for authentication (Figure \@ref(fig:generate-pat-03)).
532-
For example, a password manager is an excellent place to securely store this,
533-
and other, personal access tokens.
529+
and copy the personal access token you just generated (Figure \@ref(fig:generate-pat-03)).
530+
Since it provides access to certain parts of your account, you should
531+
treat this token like a password; for example, you should consider
532+
securely storing it using a password manager (and your other passwords and tokens, too!).
533+
Note that this page will only display the token to you once,
534+
so make sure you store it in a safe place right away. If you accidentally forget to
535+
store it, though, do not fret—you can delete that token by clicking the
536+
"Delete" button next to your token, and generate a new one from scratch.
537+
To learn more about GitHub authentication,
538+
see the additional resources section at the end of this chapter.
534539

535540
(ref:generate-pat-03) Display of the newly generated personal access token.
536541

537542
```{r generate-pat-03, fig.cap = '(ref:generate-pat-03)', fig.retina = 2, out.width="100%"}
538543
image_read("img/generate-pat_03.png")
539544
```
540545

541-
If you want to learn more about GitHub authentication,
542-
we link to two excellent sources for this in our additional resources section
543-
at the end of this chapter.
544-
545546
### Cloning a repository using Jupyter
546547

547548
The first step is to *clone* the \index{git!clone} remote repository on GitHub to create a local repository,
@@ -582,9 +583,9 @@ image_read("img/version_control/clone_04.png") %>%
582583
```
583584

584585
### Specifying files to commit
585-
Now that we have cloned the remote repository from GitHub to create a local repository,
586-
you can get to work editing, creating, and deleting files.
587-
For example, suppose we created and saved a new file (named `eda.ipynb`) that we would
586+
Now that you have cloned the remote repository from GitHub to create a local repository,
587+
you can get to work editing, creating, and deleting files.
588+
For example, suppose you created and saved a new file (named `eda.ipynb`) that you would
588589
like to send back to the project repository on GitHub (Figure \@ref(fig:git-add-01)).
589590
To "add" this modified file to the staging area (i.e., flag that this is a
590591
file whose changes we would like to commit), click the Jupyter Git extension
@@ -598,8 +599,8 @@ This opens the Jupyter Git graphical user interface pane. Next,
598599
click the plus sign (+) beside the file(s) that you want to "add" \index{git!add}
599600
(Figure \@ref(fig:git-add-02)). Note that because this is the
600601
first change for this file, it falls under the "Untracked" heading.
601-
However, next time we edit this file and want to add the changes,
602-
we will find it under the "Changed" heading.
602+
However, next time you edit this file and want to add the changes,
603+
you will find it under the "Changed" heading.
603604

604605
You will also see an `eda-checkpoint.ipynb` file under the "Untracked" heading.
605606
This is a temporary "checkpoint file" created by Jupyter when you work on `eda.ipynb`.
@@ -613,9 +614,9 @@ image_read("img/version_control/git_add_02.png")
613614
```
614615

615616
Clicking the plus sign (+) moves the file from the "Untracked" heading to the "Staged" heading,
616-
flagging this file so that Git knows we want a snapshot of its current state
617+
flagging this file so that Git knows you want a snapshot of its current state
617618
as a commit (Figure \@ref(fig:git-add-03)).
618-
Now we are ready to "commit" the changes.
619+
Now you are ready to "commit" the changes.
619620
Make sure to include a (clear and helpful!) message about what was changed
620621
so that your collaborators (and future you) know what happened in this commit.
621622

@@ -628,12 +629,12 @@ image_read("img/version_control/git_add_03.png")
628629
### Making the commit
629630

630631
To snapshot the changes with an associated commit message,
631-
we put a message in the text box at the bottom of the Git pane
632+
you must put a message in the text box at the bottom of the Git pane
632633
and click on the blue "Commit" button (Figure \@ref(fig:git-commit-01)). \index{git!commit}
633634
It is highly recommended to write useful and meaningful messages about what
634635
was changed. These commit messages, and the datetime stamp for a given
635636
commit, are the primary means to navigate through the project's history in the
636-
event that we need to view or retrieve a past version of a file, or
637+
event that you need to view or retrieve a past version of a file, or
637638
revert our project to an earlier state.
638639
When you click the "Commit" button for the first time, you will be prompted to
639640
enter your name and email. This only needs to be done once for each machine
@@ -643,9 +644,9 @@ you use Git on.
643644
image_read("img/version_control/git_commit_01.png")
644645
```
645646

646-
After "committing" the file(s), you will see there are 0 "Staged" files
647-
and we are now ready to push our changes
648-
to our remote repository on GitHub (Figure \@ref(fig:git-commit-03)).
647+
After "committing" the file(s), you will see there are 0 "Staged" files.
648+
You are now ready to push your changes
649+
to the remote repository on GitHub (Figure \@ref(fig:git-commit-03)).
649650

650651
```{r git-commit-03, fig.cap = 'After recording a commit, the staging area should be empty.', fig.retina = 2, out.width="100%"}
651652
image_read("img/version_control/git_commit_03.png")
@@ -654,7 +655,8 @@ image_read("img/version_control/git_commit_03.png")
654655
### Pushing the commits to GitHub
655656

656657
To send the committed changes back to the remote repository on
657-
GitHub, we need to *push* them. \index{git!push} To do this we click on the cloud icon with the up arrow on the Jupyter Git tab
658+
GitHub, you need to *push* them. \index{git!push} To do this,
659+
click on the cloud icon with the up arrow on the Jupyter Git tab
658660
(Figure \@ref(fig:git-push-01)).
659661

660662
(ref:git-push-01) The Jupyter Git extension "push" button (circled in red).
@@ -663,23 +665,25 @@ GitHub, we need to *push* them. \index{git!push} To do this we click on the clou
663665
image_read("img/version_control/git_push_01.png")
664666
```
665667

666-
We will then be prompted to enter our GitHub username
667-
and password, and click the blue "OK" button (Figure \@ref(fig:git-push-02)).
668+
You will then be prompted to enter your GitHub username
669+
and password. Instead of your password, though, you will
670+
need to enter the personal access token that you generated
671+
earlier. Click the blue "OK" button to initiate the push (Figure \@ref(fig:git-push-02)).
668672

669673
```{r git-push-02, fig.cap = 'Enter your Git credentials to authorize the push to the remote repository.', fig.retina = 2, out.width="100%"}
670674
image_read("img/version_control/git_push_02.png")
671675
```
672676

673-
If the files were successfully pushed to our project repository on
674-
GitHub we will be given the success message shown below.
675-
Click "Dismiss" to continue working in Jupyter (Figure \@ref(fig:git-push-03)).
677+
If the files were successfully pushed to the project repository on
678+
GitHub, you will be shown a success message (Figure \@ref(fig:git-push-03)).
679+
Click "Dismiss" to continue working in Jupyter.
676680

677681
```{r git-push-03, fig.cap = 'The prompt that the push was successful.', fig.retina = 2, out.width="100%"}
678682
image_read("img/version_control/git_push_03.png")
679683
```
680684

681685
If you visit the remote repository on GitHub,
682-
you will see that the changes now exist there via their web interface
686+
you will see that the changes now exist there too
683687
(Figure \@ref(fig:git-push-04))!
684688

685689
```{r git-push-04, fig.cap = 'The GitHub web interface shows a preview of the commit message, and the time of the most recently pushed commit for each file.', fig.retina = 2, out.width="100%"}
@@ -817,7 +821,7 @@ image_read("img/version_control/merge_conflict_03.png") %>%
817821

818822
### Handling merge conflicts
819823

820-
To fix the merge conflict, \index{git!merge conflict} we need to open the offending file
824+
To fix the merge conflict, \index{git!merge conflict} you need to open the offending file
821825
in a plain text editor and look for special marks that Git puts in the file to
822826
tell you where the merge conflict occurred (Figure \@ref(fig:merge-conflict-04)).
823827

@@ -929,5 +933,4 @@ you can expand your knowledge through the resources listed below:
929933
and [*Happy Git with R*](https://happygitwithr.com/) are great resources to take the next steps in learning about Git and GitHub.
930934
- [Good enough practices in scientific computing](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005510#sec014) [-@wilson2014best] provides more advice on useful workflows and "good enough" practices in data analysis projects.
931935
- In addition to [GitHub](https://github.com), there are other popular Git repository hosting services such as [GitLab](https://gitlab.com) and [BitBucket](https://bitbucket.org). Comparing all of these options is beyond the scope of this book, and until you become a more advanced user you are perfectly fine to just stick with GitHub. Just be aware that you have options!
932-
- If you need additional help generating and using a personal access token with GitHub,
933-
[GitHub's documentation on creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and the *Happy Git with R* [Cache credentials for HTTPS](https://happygitwithr.com/credential-caching.html) chapter are excellent additional resources for this.
936+
- [GitHub's documentation on creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and the *Happy Git with R* [cache credentials for HTTPS](https://happygitwithr.com/credential-caching.html) chapter are both excellent additional resources to consult if you need additional help generating and using personal access tokens.

0 commit comments

Comments
 (0)