Below command will remove Git credentials such as PAT globally.
git config --global --unset credential.helper
While the one below will remove stored and cached Git credentials from specific repository you are in.
git config --unset credential.helper
After removing the credentials, you can reintroduce the new PAT by setting the remote url for origin or any other branch you are using as below:
Use git set-url to set the upstream url for pushing and fetching.
git remote set-url origin https://Your-PAT-here@>github.com/xyz-user/xyz-repo.git
The git remote -v command is used to view the remote repositories associated with your Git repository. It shows the names and URLs of the remote repositories that your local repository is configured to interact with.
git remote -v
You should get an output similar to below. This shows the urls associated with your repo and if the PAT tokens (before @ sign and after https://) look updated you are golden.
origin https://ghp_asHTAS236SDFkfd23fsDf2jf90fdj2sdsd2f2fW@github.com/user/xyz.git (fetch)
origin https://ghp_2KD3954VJDFV2384392JUWEVsdiwfw902hf@github.com/user/xyz.git (push)
(invalid tokens are used for demonstration)
If you haven’t associated any git repo to your local folder yet, You can start with initializing the git repository as below:
Initialize git in that folder (root Directory)
git init
Add remote to your local git for the existing Project
git remote add origin {url}
Git add and Git Commit as needed:
git add .
git commit -m "initial commit"
Push – Push changes to the newl associated git repo
git push --set-upstrem main origin )needs checking_