0

I'm getting totally mad trying to use my two GIT users. Till today, I had only one, but now I create another one, personal and work profiles. I had two different ssh keys configured, and I've modified my .gitconfig in my user home folder with ifs condition, but nothing change... Some things I've tried (but nothing works):

  • Changing global user to new one. (In ~/.gitconfig)
  • Setting repository user (In /path/repository/.git/config)
  • Having if conditions in my home .gitconfig
  • Changing Visual Studio Code git user

I've also tried git config --list --show-origin but first user has been removed for every file shown in this list result. List returned:

file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig    credential.helper=osxkeychain
file:/Users/elenitaex5/.gitconfig       push.default=current
file:/Users/elenitaex5/.gitconfig       pull.default=current
file:/Users/elenitaex5/.gitconfig       includeif.gitdir:~/projects/.path=~/projects/.gitconfig
file:/Users/elenitaex5/projects/.gitconfig      user.name=Elena
file:/Users/elenitaex5/projects/.gitconfig      user.email=elena.maXXXo@gmail.com
file:/Users/elenitaex5/.gitconfig       user.name=Elena
file:/Users/elenitaex5/.gitconfig       user.email=elena.maXXXo@gmail.com
file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=true
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        core.ignorecase=true
file:.git/config        core.precomposeunicode=true
file:.git/config        user.name=Elena
file:.git/config        user.email=elena.mXXXo@gmail.com
file:.git/config        remote.origin.url=git@github.com:elenitaex5/homeManager.git
file:.git/config        remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

My error trying to git push:

ERROR: Permission to elenitaex5/homeManager.git denied to elenaphone.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I can't find either... user named like the alias in any file. Does anybody knows another GIT user file? Or where it can be saved?

What I wanna really do?

Having two different git users and make commits in my personal project with my personal user and use work git user to make commits in work project.

Till now, I only needed to use one, but I need two now. I've tried everything to make the second one works, even change the global git user, but nothing works. Somewhere... there's a file having first one as priority and I don't know where...

  • 1
    Can you [edit] and explain more clearly what you want to achieve, and what's currently happening? Do you want to be able to switch between these two users, or change which one appears in some particular place? Showing exactly what settings you've edited in the files you mention would also be helpful. – IMSoP Apr 30 '21 at 21:29
  • 1
    And what is your goal? Do you want to enter the *git-user* and password every time you access the repository remotely? So you can switch between your two accounts. – SwissCodeMen Apr 30 '21 at 21:33
  • I've edited main text showing my config and error @IMSoP – Elena Martín Castillo Apr 30 '21 at 21:40
  • I don't want to change every access @SwissCodeMen I want to define my user in each repository but it doesn't work either. – Elena Martín Castillo Apr 30 '21 at 21:40
  • 1
    Does this answer your question? [How can I have multiple git accounts on a single development machine?](https://stackoverflow.com/questions/50354412/how-can-i-have-multiple-git-accounts-on-a-single-development-machine) – SwissCodeMen Apr 30 '21 at 21:50
  • 1
    `git commit` uses the user.name and user.email settings to make commits. Once made, no commit can ever be changed (by anyone or anything, including `git push`) and the user settings are completely irrelevant. The `git push` operation does authentication (if it does any at all) using third-party non-Git software. The method by which this authentication works depends on both the protocol (https vs ssh for instance) and the OS, and on helper software. So you need to specify these. – torek Apr 30 '21 at 23:14
  • 2
    It looks like you're using ssh to push (based on the URLs) and are on macOS (based on the XCode thing). macOS tends to use the keychain stuff. I'm not quite sure how to manipulate that the way you'd like. – torek Apr 30 '21 at 23:16
  • Thank you @torek. Your comment has helped me to find the solution. – Elena Martín Castillo May 01 '21 at 06:42

1 Answers1

0

Thanks to @torek I'm find a solution in this question:

Store keychain credentials for multiple github accounts

I was trying use two github accounts with ssh keys, but in MAC needs keychain. So when a repository is cloned we need to do it via HTTPS including user and no vía SSH like this:

git clone https://youruser@github.com/youruser/project.git

Then I've tried a git push and IDE ask me for my password and do push action right.

Important note From August, 2021 Git no longer accept auth with password and HTTPS login will need personal access token. GIT Deprecation announcement

You can create new personal token in this link Creating a personal access token