How can I store keychain credentials for multiple Github accounts? - macos

I am running Git on OSX Mavericks and have not had issues until now. What has changed is that I'm trying to use two Github accounts on different repos on the same computer.
The problem is that the osx-keychain is storing the login information from my first account. That was terrific before, but whenever I try to commit or push from my new Github account, it is defaulting to use the keychain's username and password values, and ignoring the locally-defined git config (or even global git config!) files.
I can delete my osx-keychain, and then push to the new account, but in doing so it will create a new keychain for that account, which puts me back at square one: able to push to my secondary account with the new keychain values but locked out of my primary account.
So I'm stuck in an "either-or" situation, and I'm really hoping there's a "both" solution. Any help?
P.S. I have tried this solution, and it did not work, as the osx-keychain appeared to override the SSH Identity functionality

If you are using https url, then the solution you mention wouldn't have any effect: it is for multiple ssh keys.
Regarding https, this question mentions a few solutions, including:
By default gitcredentials only considers the domain name.
If you want git to consider the full path (e.g. if you have multiple GitHub accounts), set the useHttpPath variable to true, as described at gitcredentials.
Note that changing this setting will ask your credentials again for each URL.
By default, Git does not consider the "path" component of an http URL to be worth matching via external helpers.
This means that a credential stored for https://example.com/foo.git will also be used for https://example.com/bar.git.
If you do want to distinguish these cases, set this option to true.
Also, make sure your https url incudes your account name:
git clone https://user1#github.com/auser/aprojectX
git clone https://user2#github.com/auser/aprojectY
That will help a credential helper to known which account/password it should be looking for.
Finally, the authentication you are using for accessing a git repo hosting service has nothing to do with:
git config (--global) user.name
That last config is only for setting the author associated with your local commits.
It is not for selecting the account used to access a remote hosting website.

Related

Github project clone and push on temporary machine

I know github has changed the code push strategy and made it a token based one, even though I haven't tried it yet, but is there a way to push the code to github by using username/password as I am using a temporary laptop and don't want to save any personal details.
I am getting the below error:
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
is there a way to push the code to github by using username/password as I am using a temporary laptop and don't want to save any personal details.
You can generate a PAT just for that temporary laptop
Or you can generate an SSH key on that temporary laptop, that you will use only there, with an SSH URL.
In both instances, you can revoke (the PAT or the public registered SSH key) later on, when you no longer use that temporary laptop.

Github Change Account

Ok I'm aware this sounds stupid and I'm actually stunned this is such a problem, I changed my account under linux before but in Windows it somehow doesn't work at all.
All I want is to use another account. I tried setting new account name etc.
git config --global ***
However, while it display the right name, when I try to push it still uses my old account.
I cant believe this is so hard and wasted already way too much time on it, could someone please enlighten me (I'd prefer using bash but whatever gets the job done is good).
And for some reason google only gives me crap on this...
git config --global -e for editing the config.
As specified by the command line:
-e, --edit open an editor
This only changes the display name. To change accounts, switch your SSH key identity or HTTP credentials.
all you're doing is setting your display name
Try this
git config credential.https://github.com.username yourusername
More info on the git documentation
Ok finally found an answer:
Go to Credential Manager
Go to Windows Credentials
Delete the entries under Generic Credentials
As described in this post:
Remove credentials from Git

git-credential-winstore.exe for two GitHub logins?

I use git-credential-winstore (installed with msysgit) to store my personal GitHub account details in Window's credentials store (Control Panel -> User Accounts -> Manage your credentials -> windows credentials) I'm now trying to use a second GitHub account. I've modified the local git.config (git config user.name "foo") but when I push, it's still trying to use the personal GitHub credentials. I know I can change the repository url from https://github.com/user/project.git to https://user:password#github.com/user/project.git, but I'd rather not take the security risk by embedding credentials in the git.config. I know I can go into Control Panel and flip the credentials back and forth, but that's really annoying. Is there a way to store multiple GitHub account details in git-credential-winstore and configure each repo to use one or the other?
I have forked the git-credential-winstore to support multiple github logins.
You can find my fork here: https://gitcredentialstore.codeplex.com/SourceControl/network/forks/nickmeldrum/gitcredentialstore
(I have sent the original author a pull request but it doesn't look like he accepts them/ maintains the project anymore.)
The simplest way to use my fork would be:
Clone the repository locally: git clone https://git01.codeplex.com/gitcredentialstore
Build the project using the Debug configuration (should build from scratch with Visual Studio or MSBuild: msbuild.exe .\git-credential-winstore.sln)
Run the command: InstallLocalBuild.cmd to setup git to use this version of the credential helper
If anyone actually uses this fork and tells me about it, I will set up a proper binary download in codeplex!
Key piece of info:
In order for this to work you need to tell git the username that you want to use to connect to that particular remote in that repo. You do that by specifying it in the remote url. For example:
git remote set-url origin https://username#github.com/username/repository.git

How do I force git to prompt for credentials?

Weeks ago (and in a fog), I needed to make some changes to something hosted at github. I was directed by someone-who-knows-more-than-me (SWKMTM) via phone on exactly what to type in order to configure, pull down, modify, push back and then activate things. Part of this involved issuing instructions to git that said I as SWKMTM.
Now that I've had time to learn a bit about git/github (as well as to recall my github login information), I've gone back and tried to substitute my identity for SWKMTM on my client machine (a la git config --global user.name and git config --global user.email). After doing this, I can perform the same update activities as before. However, I have yet to be prompted to enter my github password (i.e., there is NO request to enter my github password). I'm assuming that something has been cached identifying me as SWKMTM (and that I must've done something in the earlier fog that involved entering SWKMTM's github password) -- either locally or by implicitly sending my SSH public key.
I've searched around in vain for .*rc files and configuration directories for anything that resembles credentials that might be associated with SWKMTM (in hopes of dispatching said credentials and forcing git to prompt for new ones). I've similarly failed to find anything at github that might tell if there is some sort of aliasing for public keys (and how it might be purged).
I've also tried the advised "git config -l" for any credential helper and have found none.
How can I force github to forget that I've been masquerading as SWKMTM?
[sidenote: this is on MacOS with no indication in config files that credential-osxkeychain is used. Only after using GIT_TRACE=1 on a push was it obvious where the credentialing was stored.]
user.name and user.email have nothing to do with credentials, they are just strings that are put into each commit you make to store your authorship information.
Git normally authenticates you via SSH, so you have to either copy your SSH private key from the other machine to your new client, or create a new key pair and add the public part to your github profile.
OK, after extensive discussion in the chat it turns out that Git was using the osxkeychain credential helper which provided previously stored credentials.
Remove your stored credentials from your OSX keychain or disable the crendential helper (credential.helper config option) in Git to be prompted for authentication again.

Git error: could not commit config file

I'm trying to add a new remote repository (GitHub) to an existing project, and I'm getting an error that I've never seen before, and don't understand:
$ git remote add github git#github.com:me/myrepo.git
error: could not commit config file .git/config
What? Why would I commit the git config file? And how do I make this stop happening?
I'm on a Mac, with a relatively fresh install of most of my tools. I think this is the first time I've tried to add a remote to a repo on this machine.
Some git commands modify the git config file. One of them is git remote add, because the remote is stored in the config file.
To avoid problems with several git processes modifying the config file simultaneously, git will lock the config file before changing it (by writing a lock file), and release the lock afterwards (by renaming the lock file to the config file).
The error message
error: could not commit config file .git/config
means that git could not properly release this lock. This probably means that either another process was working on the same file, or there was some kind of filesystem error (or there's a bug in git or your OS/libraries).
Unfortunately, git does not tell you what exactly was the problem, so you'll have to manually debug this. You could try running git with dtruss to see what exactly is going wrong.
This could be a permissions issue, especially for automated jobs running on Windows that can have fewer permissions than an interactive login of the same user. From this answer on ServerFault:
Each logon session to a Windows (NT-based versions, that is) machine
has a "security token"-- a data structure that describes, amongst
other things, the groups that the user represented by the token is a
member of.
The "Interactive" identity isn't a group that you can manually place
members into, but rather is added by the operating system,
automatically, when a security token is constructed for a user who has
logged-on via the Windows Graphical User Interface. This is similar to
the "Network" identity, which is added automatically to tokens created
for users who are accessing the machine via the network.
These automatically-generated group memberships allow you to construct
permissions that might allow or deny access to resources based on how
the user is accessing the machine. This supplements the permission
system's default behavior of arbitrating access based on who is
accessing the resource.

Resources