1 - How To Configure GIT Credentials For One Repo Instead Globally Set or Manage Multiple Git Configs For Specific Repo
1 - How To Configure GIT Credentials For One Repo Instead Globally Set or Manage Multiple Git Configs For Specific Repo
io/blog/multiple-git-configs-personal-github-token
If you use Git, chances are you are using global Git config (config that applies to all repos
you create) on your machine. Sometimes, you may want to set up a different Git config for a
one-off repo on that machine and this tutorial will walk you through doing that using a
personal Github token. I find it simpler to use a token rather than going through separate SSH
configs.
Let’s say you created a Git repo which should be shared on Github under a different account.
It’s simple. There are 3 steps to do so:
Create Git repo and go to that folder. Then use these commands to define different git config
for that repo:
If you have a personal access token in Github already, you can copy it and skip the next step.
Create a new token for repo purposes. It is a good practice to set an expiration date for your
token. Copy the token value. You will need it in the next step.
If git remote has not been set up for this repo, do so:
Note: if git remote has already been set up for this repo but needs to be updated to include the
token:
Now when you push your repo to remote, it will go under github.com/github-username
Bonus
If you already pushed some commits under a wrong Github profile, you can change history of
those commits and only rewrite author value.
git log
Prartical [SUCCESS]
% git push --set-upstream origin master
remote: Permission to kkamal123/TestGit.git denied to hatizaz-nisum-com.
fatal: unable to access 'https://github.com/kkamal123/TestGit.git/': The requested URL returned error: 403
Note: if git remote has already been set up for this repo but needs to be updated to include the
token:
git remote set-url origin https://[email protected]/github-username/Repo-
Name.git
Verification
You cannot push changes to master branch, so we tried to push changes to feature branch
below.