-1

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   user.email=firstemail@gmail.com
...

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 = secondemail@gmail.com
[remote "origin"]
    url = https://github.com/secondusername/secondusername.github.io.git
    fetch = +refs/heads/*:refs/remotes/origin/*

what am I doing wrong??

dapidmini
  • 1,490
  • 2
  • 23
  • 46
  • This is odd, because the [answers here](https://stackoverflow.com/q/42167345/3216427) (not a duplicate question!) suggest that what you did should have worked. – joanis Mar 20 '22 at 16:17
  • `git config --list --show-origin` will list all the entries : add ` | grep user` afterwards and you will see both the global and the local entry being mentioned – LeGEC Mar 20 '22 at 17:54
  • hmm.. is my question not thorough enough or something? what's with the downvote? – dapidmini Mar 21 '22 at 03:46

1 Answers1

3

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://seconduser@github.com/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 :

Multiple GitHub Accounts & SSH Config

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • I'm sorry, but are you sure the syntax is correct? because yours look like a bitbucket url instead of github.. if I were to try yours then it would look like this, right? `git remote set-url https://seconduser@github.com/seconduser/seconduser.github.io.git` don't you think it's a bit weird? also, when I run `git remote get-url origin` it already says `https://github/seconduser/seconduser.github.io.git` – dapidmini Mar 21 '22 at 03:59
  • 1
    @dapidmini : you need to somehow log in as `seconduser` on github. The `https://user@somehost.com/` syntax is a rather standard way to provide a username together with an http/https url, and understood by the satndard browsers and command line tools (e.g : `wget` or `curl`), and AFAIK it should work with github. I personnally use ssh and ssh keys, and use a setup as described in the link to be able to select which account to use. – LeGEC Mar 21 '22 at 04:08