I'm working on multiple projects and those projects are connected to different github account. my main project's config was set using git config --global user.name "firstusername"
and the second project used git config user.name "secondusername"
. but when I tried connecting the second one to github using git push -u origin main
, it says Permission to secondusername/secondusername.github.io.git denied to firstusername
.
when I open gitbash on the second project folder and run git config user.name
it gives secondusername
, but when I run git config --list --show-origin
the credentials says like this
...
file:C:/Users/home/.gitconfig user.name=firstusername
file:C:/Users/home/.gitconfig [email protected]
...
but when I checked the secondproject/.git/config
file the contents looks like this
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[user]
name = secondusername
email = [email protected]
[remote "origin"]
url = https://github.com/secondusername/secondusername.github.io.git
fetch = refs/heads/*:refs/remotes/origin/*
what am I doing wrong??
CodePudding user response:
user.name
and user.email
are only used to write the name of the author and/or committer when you create commits on your local repo (git commit
, git merge
, git rebase
, ...).
The credentials to connect to a remote service, on the other hand, should be somehow provided through the remote's url.
Try changing the remote url of your second repo to : https://[email protected]/seconduser/...
Another way is to access github through ssh, and set up your local workstation (its ssh_config
in particular) to be able to easily target both accounts :