Skip to content

Commit d644968

Browse files
committed
added section on personal access tokens. Closes #306
1 parent efc4fbe commit d644968

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

img/generate-pat_01.png

120 KB
Loading

img/generate-pat_02.png

402 KB
Loading

img/generate-pat_03.png

202 KB
Loading

version-control.Rmd

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ version control: you won't be able to see, interpret, or find changes in the his
468468
of any of the actual content of your project!
469469

470470
## Working with local repositories using Jupyter {#local-repo-jupyter}
471+
471472
Although there are several ways to create and edit files on GitHub, they are
472473
not quite powerful enough for efficiently creating and editing complex files,
473474
or files that need to be executed to assess whether they work (e.g., files
@@ -477,10 +478,70 @@ remote repository that was created on GitHub to a local coding environment. Thi
477478
can be done by creating and working in a local copy of the repository.
478479
In this chapter, we focus on interacting with Git via Jupyter using
479480
the Jupyter Git extension. The Jupyter Git \index{git!Jupyter extension} extension
480-
can be run via Jupyter on your local computer, or on a JupyterHub server.
481+
can be run by Jupyter on your local computer, or on a JupyterHub server.
481482
*Note: we recommend reading Chapter \@ref(getting-started-with-jupyter)*
482483
*to learn how to use Jupyter before reading this chapter.*
483484

485+
### Generating a GitHub personal access token
486+
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.
491+
There are several methods to do this,
492+
but for beginners we recommend using the HTTPS method
493+
because it is easier to do and requires less setup.
494+
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.
498+
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).
503+
Once there, click "Generate new token" (Figure \@ref(fig:generate-pat-01)).
504+
Note that you may be asked to re-authenticate with your username
505+
and password to proceed.
506+
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).
508+
509+
```{r generate-pat-01, fig.cap = '(ref:generate-pat-01)', fig.retina = 2, out.width="100%"}
510+
image_read("img/generate-pat_01.png")
511+
```
512+
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
518+
and click the green "Generate token" button (Figure \@ref(fig:generate-pat-02)).
519+
520+
(ref:generate-pat-02) Webpage for creating a new personal access token.
521+
522+
```{r generate-pat-02, fig.cap = '(ref:generate-pat-02)', fig.retina = 2, out.width="100%"}
523+
image_read("img/generate-pat_02.png")
524+
```
525+
526+
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.
534+
535+
(ref:generate-pat-03) Display of the newly generated personal access token.
536+
537+
```{r generate-pat-03, fig.cap = '(ref:generate-pat-03)', fig.retina = 2, out.width="100%"}
538+
image_read("img/generate-pat_03.png")
539+
```
540+
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+
484545
### Cloning a repository using Jupyter
485546

486547
The first step is to *clone* the \index{git!clone} remote repository on GitHub to create a local repository,
@@ -865,7 +926,8 @@ Now that you've picked up the basics of version control with Git and GitHub,
865926
you can expand your knowledge through the resources listed below:
866927

867928
- GitHub's [guides website](https://guides.github.com/) and [YouTube channel](https://www.youtube.com/githubguides),
868-
and [Happy Git](https://happygitwithr.com/) are great resources to take the next steps in learning about Git and GitHub.
929+
and [*Happy Git with R*](https://happygitwithr.com/) are great resources to take the next steps in learning about Git and GitHub.
869930
- [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.
870931
- 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!
871-
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.

0 commit comments

Comments
 (0)