From 32ce2d64041a149d0bb3ed20541f23fef651a77f Mon Sep 17 00:00:00 2001 From: Neal Magee Date: Tue, 13 Aug 2024 09:21:57 -0400 Subject: [PATCH] Better wording around tokens --- docs/creating-repositories.md | 18 +++++++++++++++++- docs/git-advanced.md | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/creating-repositories.md b/docs/creating-repositories.md index f383a30..4da75cf 100644 --- a/docs/creating-repositories.md +++ b/docs/creating-repositories.md @@ -39,16 +39,22 @@ Assuming you are authenticating to GitHub using SSH keys, here are the steps to 1. Within [GitHub](https://github.com/) find the existing repository you want to clone. 2. From the repository page, find the blue "Code" button, and select the SSH tab within the dropdown. If you are using a PAT for authentication, use the HTTPS address. 3. Copy the address, which will look something like `git@github.com:UVADS/git-basics.git` (SSH) or `https://github.com/UVADS/git-basics.git` (HTTPS). -4. In the command-line on your local computer, clone the repo: +4. In the command-line on your local computer, clone the repo. If using an SSH key to authenticate to GitHub, use this format: ``` git clone git@github.com:UVADS/git-basics.git ``` + If using a PAT to authenticate to GitHub, be sure to insert your token in the clone command like this: + + ``` + git clone https://ghp_xxxxxxxxxxxxxxx@github.com/UVADS/git-basics.git + 5. This will create a new subdirectory with the name of the repository. You can change the name of the directory if you like. 6. If there are multiple branches in the GitHub repository and you want to clone them all, use these commands (using this repository as an example): ``` + # Using SSH git clone git@github.com:UVADS/git-basics.git cd git-basics/ git fetch --all @@ -57,6 +63,16 @@ Assuming you are authenticating to GitHub using SSH keys, here are the steps to done ``` + ``` + # Using a PAT + git clone https://ghp_xxxxxxxxxxxxxxx@github.com/UVADS/git-basics.git + cd git-basics/ + git fetch --all + for branch in `git branch -r | grep -v HEAD`; do + git checkout -b $branch $branch + done + ``` + 7. Note that if you create a new, empty repository within GitHub, it is helpful to tick the box to include a `README.md` file by default. This ensures that a default branch (named `main`) will be created for you. diff --git a/docs/git-advanced.md b/docs/git-advanced.md index 5705fa5..c3faaae 100644 --- a/docs/git-advanced.md +++ b/docs/git-advanced.md @@ -214,6 +214,22 @@ destination git@github.com:mst3k/some-repo.git (fetch) destination git@github.com:mst3k/some-repo.git (push) ``` +## Change from SSH to Token Authentication + +If you cloned an existing repository using SSH, you can easily update your local `git` to use tokens instead. + +From within the repo, and assuming you already have a PAT created, issue this command (inserting your token in the URL): + +``` +git remote set-url origin https://ghp_xxxxxxxxxxxxxxx@github.com/UVADS/git-basics.git +``` + +Or if you have saved your PAT as a local `env` variable, use that instead: + +``` +git remote set-url origin https://$GITHUB_TOKEN@github.com/UVADS/git-basics.git +``` + ## Bonus - So You Think You Know Git In this video Scott Chacon, one of the co-founders and original developers of GitHub, talks about buried and advanced features in Git and GitHub.