My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Tuesday, March 10, 2026

How to set new Github PTA when old expired

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

  1. Log into GitHub.com and go to your Settings (click your profile photo in the top right).
  2. On the left sidebar, scroll to the bottom and click Developer settings.
  3. Click Personal access tokens -> Tokens (classic).
  4. Click Generate new token (classic).
  5. Note: Give it a name (e.g., "MacBook Pro").
  6. Expiration: Choose a duration (or "No expiration" if you prefer).
  7. Scopes: Select the repo checkbox (this is required for push/pull access).
  8. Click Generate token and copy the token immediately. You will not be able to see it again.

To update your Personal Access Token (PAT) because Git is still using an old, expired one, you must clear the existing credentials from your system's storage so Git can prompt you for the new one.
1. Clear Old Credentials (Required)
Choose the steps for your specific Operating System:
  • Windows:
    1. Open the Start Menu, search for "Credential Manager", and open it.
    2. Select Windows Credentials.
    3. Find entries for git:https://github.com and click Remove.
  • macOS:
    1. Open Keychain Access (use Command + Space and type it).
    2. Search for github.com.
    3. 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

**But sometimes this step does not work. For that use following:
git remote set-url origin https://github.com


Step 2: Set the Token in your Terminal
Since you already cleared your Keychain earlier, Git will now ask you for the new token the next time you try to connect.
  1. In your terminal, run:
    git pull origin main
  2. Username: Type your GitHub username and press Enter.
  3. 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.
But in my case I was getting an error - git pull origin main says fatal: repository 'https://github.com/' not found



Run this command to fix it (replace your-username and your-repo-name with your actual names):
bash
git remote set-url origin https://github.com
Use code with caution.
Now, try to pull again:
bash
git pull origin main
Use code with caution.
What will happen next:
  1. It will ask for your Username: Type it and hit Enter.
  2. It will ask for your PasswordPaste your new PAT here and hit Enter. (You won't see any characters appear while pasting).
Why it says "Not Found":
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

    Permissions Required for Your PAT
    Depending on which type of token you created, ensure these settings are enabled:
    • 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


Saturday, February 28, 2026

How To undo a git add operation (unstage files)

To undo a git add operation (unstage files), the recommended command is git restore --staged. This moves changes from the staging area back to the working directory without losing any modifications.

Recommended Method: git restore --staged
This command is the preferred method in modern Git (versions 2.23+) because it is more intuitive and safer for this specific task.
  • Unstage a specific file:
    bash
    git restore --staged <filename>
    
    (Replace <filename> with the actual name of your file, e.g., git restore --staged index.html).
  • Unstage all files:
    bash
    git restore --staged .
Alternative Method: git reset
Before git restore was introduced, the git reset command was used to unstage files, and it still works.
  • Unstage a specific file:
    bash
    git reset <filename>
    
  • Unstage all files:
    bash
    git reset

How To change a Git branch name

To change a Git branch name, you first rename the branch locally using git branch -m and then update the remote repository.

Renaming a Local Branch
You can rename a local branch in one of two ways:
  • If you are on the branch you want to rename:
    bash
    git branch -m <new-name>
    
    For example: git branch -m feature/new-login.
  • If you are on a different branch:
    bash
    git branch -m <old-name> <new-name>
    
    For example: git branch -m feature/old-login feature/new-login.
Renaming a Remote Branch
Renaming a branch that has already been pushed to a remote repository (like GitHub or GitLab) requires a few extra steps and team coordination.
  1. Rename your local branch using one of the methods above.
  2. Push the newly named local branch to the remote repository. This effectively creates a new branch on the remote.
    bash
    git push origin -u <new-name>
    
    The -u (or --set-upstream) flag is important as it links your local branch to the new remote branch.
  3. Delete the old branch from the remote repository to avoid confusion:
    bash
    git push origin --delete <old-name>
    
  4. Update settings on your Git host (e.g., GitHub, GitLab, Bitbucket) if the renamed branch was the default branch or if there were branch protection rules, CI/CD pipelines, or open pull requests associated with the old name.