I ran into a situation. My Personal Access Token on Git expired and I wanted to generate and set in my git terminal locally. The problem was that my git was still taking old PTA from command line. I kept on asking for old PTA which was now expired. Let me walk you through what was done next.
But first - Let's learn to set a new Personal Access Token (PAT) on your Mac, you need to first generate it on the GitHub website and then enter it into your terminal when prompted.
Step 1: Generate a New PAT on GitHub
- Log into GitHub.com and go to your Settings (click your profile photo in the top right).
- On the left sidebar, scroll to the bottom and click Developer settings.
- Click Personal access tokens -> Tokens (classic).
- Click Generate new token (classic).
- Note: Give it a name (e.g., "MacBook Pro").
- Expiration: Choose a duration (or "No expiration" if you prefer).
- Scopes: Select the
repocheckbox (this is required for push/pull access). - Click Generate token and copy the token immediately. You will not be able to see it again.
- Windows:
- Open the Start Menu, search for "Credential Manager", and open it.
- Select Windows Credentials.
- Find entries for
git:https://github.comand click Remove.
- macOS:
- Open Keychain Access (use Command + Space and type it).
- Search for
github.com. - Right-click the entry and select Delete "github.com".
- Linux (Command Line):
- Run:
git config --global --unset credential.helper. - If you used the "store" helper, delete the credentials file:
rm ~/.git-credentials
git remote set-url origin https://github.com- In your terminal, run:
git pull origin main - Username: Type your GitHub username and press Enter.
- Password: Paste your new PAT and press Enter.
- Note: The terminal will not show any dots or characters while you paste. This is normal security behavior.
- It will ask for your Username: Type it and hit Enter.
- It will ask for your Password: Paste your new PAT here and hit Enter. (You won't see any characters appear while pasting).
In your previous steps, the remote URL accidentally got set to
https://github.com/. GitHub doesn't see any code there, so it tells you the "repository" doesn't exist. Pointing it back to the full URL fixes this. eg: git remote set-url origin https://github.com/Anwar/Artudio- Fine-grained Token (Recommended):
- Repository access: Select "Only select repositories" and choose your specific repository (e.g.,
Anwar-Faiz/artudio), or select "All repositories". - Permissions: Under "Repository permissions", find "Contents" and change the access to Read and Write.
- I also give Pull Request Read and Write
- Metadata: as Read only
No comments:
Post a Comment