Authorization with Token | Bondar Academy
Course: Git and GitHub Fundamentals
Module: Working with Git and GitHub
Instructor: Artem Bondar
Lesson Summary
This lesson covers the process of creating a personal access token on GitHub for accessing repositories from an independent terminal, rather than using the built-in terminal in Visual Studio Code . Steps to Create a Personal Access Token Log in to your GitHub account. Click on your account icon and select Settings . Scroll down to Developer settings . Select Personal access tokens and then Tokens classic . Click on Generate new token . Provide your GitHub account password. Fill in the token details: Name: e.g., "my token" Expiration: Choose duration (default is 30 days, or select "No expiration"). Access: Check repo for full repository access. Click Generate token and save the token securely, as it will not be displayed again. Using the Token for Git Operations To use the token for committing and pushing changes: Open an independent terminal. Navigate to your project directory using cd . Create a new branch with git branch new-branch and switch to it using git checkout new-branch . Make changes to your files. Stage changes with git add and commit using git commit -m "Your message" . Push changes with git push . When prompted for a username, enter your GitHub username, and for the password, use the personal access token instead of your account password. After successfully pushing, you can create a pull request on GitHub to merge your changes. This method allows for secure access to your repositories without using a username and password directly.
Video Transcript
In this lesson, I will show you how to create personal access token on GitHub. Sometimes, you may want to work with your repository in independent terminal, instead of terminal in VS Code. In this case, you will need this token to get access to your repository. So let's jump into it. All right. In the previous lesson, I have showed you how to authorize your GitHub account with Visual Studio Code in order to perform the operations such as git pull, git push, and so on. But if you would like to use a different IDE or maybe perform your operations just independently in the terminal, not in the terminal that is built in into Visual Studio Code, you will need to use a credentials to authorize your git push request, to write some changes to remote repositories. So how to do that? How to use those credentials? So going back to GitHub, and we will need to create a personal access token because you will not be able to use just the username and password. So we need to click on the icon of your account right here, click into settings. Then in settings, scroll all the way down to developer settings, click on personal access tokens, and select tokens classic. Click on that. Now click on the button generate a new token, generate new token classic. We need to provide the password from GitHub account, and here's the interface for the token creation. First of all, provide the name of the token. For example, my token. Then provide the expiration. How long do you want this token to be valid? Right now by default, it's 30 days, but we can say 90 days custom day or no expiration. Let's say no expiration. Then we need to define what the access for this token will be. Click on this repo to provide a full access to the repository. That's all we need. Scroll down and create generate token. Click on this button. This is the value that you need somewhere securely to save. This value will not be available for you to view next time. If you go back to this area, you will need to generate token again. So you can copy this value and save to your password manager, for example. And that's pretty much it. The token is created. My token available under your account. Okay, going back to repositories. Now let's try to use this token to perform a new commit and push to this repository. Going back to our application, and let's say we want to work with the test file, make some new changes, create a new commit and push the changes to this text file. I will create a new branch and I will use a fully terminal approach to work with this change. Open the terminal. This is independent terminal, not related to Visual Studio Code. CD PW navigated to the app. Git branch, new branch. New branch. A new branch created. Git checkout, new branch. Switch to the new branch. Git branch. We can confirm. We switched to a new branch. Now we can make some changes over here. New change, something like that. Now we need to commit those changes. Git add. Add those changes and git commit dash M. Edit new line to TXT and hit enter. All right, we saved those changes. If we navigate, go back over here. This is correctly reflected in the Visual Studio as well. Now we need to push these changes to the remote repository. I type git push and we see the same message that we need to set upstream. Copy this line, set upstream, hit return. And now Git is asking us for username and password. For username, you provide the username for your GitHub account. In our example, it will be git user dash Bonder Academy. And I type here, git user dash Bonder Academy. Hit enter. And for the password, we need to provide the token that we generated on the previous step, not the actual password from the account. Only a personal access token will work. Hit enter, and we successfully pushed the branch. Going back, now we see this branch is available on the GitHub. Create pull request. Create pull requests. Checking for merge conflict is good. Merge pull request, confirm merge, and delete branch. Going back, checking the master branch, edit new text, and new change is available in the master branch in the text file that we just modified. So this is a second approach, how you can authorize your session with the GitHub and update your changes to the remote repository. All right, that's it, guys, and see you in the next lesson.