How I Access a GitHub Repository from My Local Machine Using a Personal Access Token (PAT)
Hi, I’m Raees Qazi, the Founder and CEO of Briller Technologies, and as a learner of DevOps and automation, I’m always exploring new ways to improve my workflows. Today, I want to share how I access GitHub repositories from my local machine using a Personal Access Token (PAT). If you’re new to this, don’t worry — I’ll explain everything in simple terms.
When working with GitHub, there are typically two ways to authenticate from your local machine: using a Personal Access Token (PAT) or SSH. In this blog, I’ll walk you through how I use a PAT to securely access and interact with my repositories.
What is a PAT?
A Personal Access Token (PAT) is like a password, but much more secure. You generate it in your GitHub account and use it to authenticate actions like pushing and pulling code. Instead of using your GitHub password each time, the token acts as a one-time password for Git operations.
Additionally, you can set an expiration date for your token (up to 30 days), which enhances security by limiting the time the token can be used.
Steps to Create a PAT:
To create and use a Personal Access Token (PAT), here’s the process I follow:
1. Log in to GitHub: First, I log into GitHub using my username and password.
2. Go to Settings: Once logged in, I click on my profile icon in the top-right corner and select Settings from the dropdown.
3. Access Developer Settings: On the left sidebar, I scroll down and click on Developer Settings.
4. Select Personal Access Tokens: Under Developer Settings, I click on Personal Access Tokens.
5. Generate New Token: I click Generate New Token. Here, I select the permissions I need for the token (like access to my repositories).
6. Save the Token: After generating the token, GitHub shows it once. I copy the token and make sure to save it in a safe place (like a password manager or a secure text file).
How to Use the Token:
Once I have the token, the next step is to set it up to authenticate my Git commands. Here’s how I do it:
1. Check the Remote URL: First, I need to make sure my local repository is linked to the correct GitHub repository. To check, I run the following command:
2. git remote -v
This command shows me the remote repository URL. If no remote is set, I use this command to add one:
git remote add origin <URL of your repo>
3. Set the Remote URL with the Token: Next, I update the remote URL to include my token for authentication. This is how I do it:
4. git remote set-url origin https://<your-token>@github.com/username/repository.git
Here, I replace <your-token> with the token I generated earlier, and <username/repository> with the actual repository path on GitHub.
5. Push and Pull Using the Token: Now that the remote URL is set up with the token, I can push my changes or pull updates from the repository. The token will automatically authenticate my actions.
Wrapping It Up
That’s it! With these steps, I can securely access my GitHub repositories using a Personal Access Token (PAT). It’s simple, secure, and makes it easy to interact with GitHub directly from my local machine. Whether you’re working on automation, DevOps, or just coding, using PAT is an effective way to keep your GitHub workflows smooth and secure.
I hope you found this blog helpful. If you’re new to DevOps or GitHub, give this a try and see how it works for you!
Here is the YouTube Link: https://youtube.com/@raeesq.?si=v_QK6Q2XXMf9mKep
Thanks for reading!

Comments
Post a Comment