"No secret key" error when signing git commit on Windows - windows

I'm getting this error when trying to sign a commit:
git commit -S -m "test"
gpg: skipped "EF617ACA9EC3XXXX": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object
This is the output of gpg --list-secret-keys --keyid-format LONG
The key is present there
sec rsa4096/EF617ACA9EC3XXXX 2020-05-17 [SC] [expires: 2022-05-17]
AD68154000A712DCD161D826EF617ACA9EC3XXXX
uid [ultimate] name <email#gmail.com>
And this is git config with the same key
user.signingkey=EF617ACA9EC3XXXX
user.email=email#gmail.com
Any idea what's wrong?

git config --global gpg.program "c:/Program Files (x86)/GnuPG/bin/gpg.exe"
I installed with Kleopatra and generated my key within that. I was unable to create a commit until I ran the command above.

Check first the git config gpg.program to see if this is gpg or gpg2 (as in here).
And type where gpg nd where gpg2 to check which path is considered for the GPG program.
I suggested to set gpg.program to gpg2, and copy your gpg.exe (assuming its version is a 2.x) to gpg2.exe
That should force Git/GPG to act as gpg2.

In case anyone is a dufus like me I was getting this error because I had the gitkey wrong while directly editing the file via: git config --global -e or code ~/.gitconfig or whatever flavor of editor you enjoy.
singingkey πŸŽΆπŸ”‘ instead of
signingkey πŸ€¦β€β™‚οΈ

Was facing the same issue in windows 10 git bash. Doing this solved my problem. You could find this path by running where gpg
$ git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"

Another potential issue/resolution:
Make sure the email you set in Github is verified and that it exactly matches the email you used when you generated your GPG key.

Had this same problem on Windows 11 when trying to get GitHub Desktop to work.
The answer given here solved the issue for me:
git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"

Related

Offending RSA key in /u/.ssh/known_hosts during git clone on windows

I am trying to git clone a repository on my windows machine, with:
git clone -b <branch> ssh://<host>
I have already added the keys, and deleted the existing known_hosts file in C:\Users<username>.ssh
But the git clone fails with
###########################################################
# WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! #
###########################################################
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the DSA key sent by the remote host is
SHA256:<fingerprint>.
Please contact your system administrator.
Add correct host key in /u/.ssh/known_hosts to get rid of this message.
Offending RSA key in /u/.ssh/known_hosts:6
Where is this known_hosts (/u/.ssh/known_hosts) file? C:\Users<username>\.ssh does not have this file, I was expecting for it to get created in the git clone command.
The same command works fine on my ubuntu PC.
The mentioned path has an linux-ish look, which indicates you were probably running your command from git-bash.
The simplest way to fix your issue is to edit the mentioned file (/u/.ssh/known_hosts) from a git-bash shell.
Check your environment variable HOME: in a CMD, type set HOME.
If it is set to U:\ (translated, in a bash session, to /u/), that would explain why SSH is lookig for information (keys, config file, known_hosts file, ...) in U:\.ssh
Change your HOME environment variable (back to, for instance, %USERPROFILE%) to make sure SSH looks for keys where you expect it.

Git config error when trying to set name and email

I'm new to Git and Github and I'm just trying to set up my desktop client to be able to upload my projects.
When trying to commit I get this error from the desktop client:
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'wsm1u#DESKTOP-5ICE6RR.(none)')
So then I use Windows Powershell and get this error:
PS C:\WINDOWS\system32> cd $HOME
PS C:\Users\wsm1u> git config --global user.email "wsm1usa1va1b#gmail.com"
>>
error: could not lock config file C:/desktop/.gitconfig: No such file or directory
Basically, I think the problem is that Git is searching for the config file in the wrong place, but I'm not sure how to have it search elsewhere.
Here are the solutions I've tried:
uninstalling and reinstalling Git
running Windows Powershell as admin (this gives back the same error message)
Pasting a copy of .gitconfig in my desktop (this didn't work so I deleted it)
running git lfs install --force to reset Git configuration, this gave the error message warning: error running C:\Program Files\Git\mingw64\libexec\git-core\git.exe 'config' '--includes' '--global' '--replace-all' 'filter.lfs.clean' 'git-lfs clean -- %f': 'error: could not lock config file C:/desktop/.gitconfig: No such file or directory' 'exit status 255' Run "git lfs install --force" to reset Git configuration.
Tried to locate a .gitconfig.lock file as per this solution: https://askubuntu.com/questions/258288/trouble-setting-up-git-error-could-not-lock-config-file
Here is my system info: System information
Thank you for your help! :)
TL;DR
I set my HOME
Found some gitconfig files in my trash and deleted them
I was able to set name and email through cmd as admin.
I was able to commit!
Long version
I ran cmd: set HOME and got
C:\Users\wsm1u>set HOME HOME=C:\desktop HOMEDRIVE=C: HOMEPATH=\Users\wsm1u
I went to: https://superuser.com/questions/246731/how-do-i-change-homedrive-homepath-and-homeshare-in-windows-xp β‡’ Marc B's solution (setting home path through "advanced system settings")
Committed through GitHub desktop -> got "tell me who you are" error
Set email in cmd -> got blank return
Set name -> got "permission denied" error
Ran cmd as admin
Set name -> got blank return
Tried to commit again and "Please tell me who you are" error again.
Ran git.bash as admin and set name/email then ran git config β€’list and got correct name and email returned
Tried to commit and got "please tell me who you are" error again
I tried creating a copy of my github desktop client in the program files directory because that is where my git directory is located. I thought maybe the client would only be able to find it that way (this made sense in my head) and that didn't work, so I deleted it.
While I was in progam files though I noticed that there was a .gitconfig there and so I deleted that, then I emptied my trash and noticed there were more in there.
Then I ran git config β€’list again and the name and email were gone from the return
Then I set name and email again in cmd as admin and I WAS ABLE TO COMMIT FOR THE FIRST TIME!!!

Push Changes to Git not Functioning

Every time I want to commit the command "git push heroku master" I am asked in the PowerShell to enter the credentials. When I enter heroku credentials (which is connected to git by default) I get the error message.
But, when I type the credetials contained in the netrc file in my home directory, then the thing functions. The password is however hashed in my opinion. How can I avoid entering credentials every time I want to push changes to git?
UPDATE:
PS C:\Users\Dragan\heroku_workspace\python-getting-started> git push heroku master
github --credentials get: github: command not found
Username for 'https://git.heroku.com': my-email#hotmail.com
Password for 'https://my-email#hotmail.com#git.heroku.com':
github --credentials erase: github: command not found
remote: ! WARNING:
remote: ! Do not authenticate with username and password using git.
remote: ! Run `heroku login` to update your credentials, then retry the git command.
remote: ! See documentation for details: Https://devcenter.heroku.com/articles/http-git#authentication
fatal: Authentication failed for 'https://git.heroku.com/mysterious-river-71834.git/'
A common mistake is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking the ssh button left to the URL field and updating the URL of your origin remote like this:
git remote set-url origin git#github.com:username/repo.git
or if your repository already then click green button CLONE OR DOWNLOAD and select use SSH
Enable SSH authentication
$ heroku create --ssh-git
Redirect tall HTTPS calls to SSH ( If you want to always use SSH Git with Heroku on a particular machine)
$ git config --global url.ssh://git#heroku.com/.insteadOf https://git.heroku.com/
To generate a public key:
ssh-keygen -t rsa Press enter at the first prompt to use the default file location. Next, type a secure passphrase for the key.
If you are using v1.9.3 or later Git for Windows, you can do the following
git config --global credential.helper wincred
Please note that this mechanism stores your username/password in Windows Credential Store.
In relatively newer versions, Git Credential Manager for Windows is bundled with Git for Windows and enabled by default, you might have to override credential.helper configuration for Heroku. GCM seems designed for VSTS and GitHub and I am not how it will behave with other servers.
Worked for me:
Run heroku login using the windows command prompt cmd.exe. This will drop your API key into your _netrc at which point you can open up cygwin or git bash and do whatever you need to
From .gitconfig remove the helper = manager line so that it is no longer registered as a credential helper and stops it from showing up.
(in C:\Users\username\.gitconfig )
Rename _netrc file to .netrc on Windows 7 in the user dir:
cd %home%
REN _netrc .netrc
see:
'git push heroku master' is still asking for authentication
https://github.com/heroku/cli/issues/84#issuecomment-170689175

Git uses invalid author name in commits

When i commit git uses not company mail but my personal, which i use in chrome, i do commits using ssh URL and ssh key contains correct mail address, in git lab commits are also under my name but when i open commit author there is my personal URL with nick name. Usually i commit using intellij idea but same result with console commands
I have already reinstalled git and replaced ssh key with new one but it still use my personal nick as author.
So how can i change author of new commits, so it'll be by default correct?
i don't want to write console commands with author argument every time i commit.
OS windows 7
You can update your config file from Git Bash:
git config --global user.name "[Your name]"
git config --global user.email [email address]
This will set a global username and email.
To check your current settings:
git config --list
Update your Git config file with required Name and Email Id.

How do I update the password for Git?

I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (thanks Adobe!).
Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (Authentication failed for 'https://______.git'), but I'm forgetting how to update the cached password on my iMac. Somehow I've been unable to find it on Google or Stack Overflow, though it seems to me it should be rather straightforward...
To fix this on macOS, you can use
git config --global credential.helper osxkeychain
A username and password prompt will appear with your next Git action (pull, clone, push, etc.).
For Windows, it's the same command with a different argument:
git config --global credential.helper wincred
None of the other answers worked for me on MacOS Sierra 10.12.4
Here is what I had to do:
git config --global --unset user.password
Then run your git command (ex. git push) and reenter your username and password.
In Windows 10 with Git
Remove/update related Credentials stored in Windows Credentials in >>Control Panel\All Control Panel Items\Credential Manager
Or you can just use the search bar and search for "CredentialManager" or "Windows Credentials", which should return an entry to open that Control Panel pane (at least for English users).
The only way I could modify my git password was to go to Credential Manager in Windows (Windows Key + type 'credential') and edit the git entry under Windows Credentials πŸ‘’ Generic Credentials.
Note: Not listed alphabetically
I had the same problem, and the accepted answer didn't help me because the password wasn't stored in the keychain. I typed:
git pull https://myuser#bitbucket.org/mypath/myrepo.git
Then console asked me for my new password.
In windows 10 as mentioned above by #Imran Javed you can find Generic Credentials at :
Control Panel\All Control Panel Items\Credential Manager --> Windows Credentials
find your git server and than you can update password by clicking edit button.
For Mac
If you have multiple remote repositories (Github, Bitbucket, Job, etc.)
1) run in the project directory
git config --unset user.password
2) run remote git command (ie. git push or git pull)
Git will prompt you to reenter your user.name and user.password for this repository
Or you can do it globally if you have only one remote repository
git config --global --unset user.password
If you are MAC user then you can open KeyChain Access Application from finder and then look for your account listed there. Just click on it and update your password.
Now give a try and things will fall in place.
link for reference: Updating your credentials via Keychain Access
None of the other answers worked for me on MacOS Big Sur 11.3.1
I had Two-Factor Authentication enabled on Github, this makes is so you will fail when entering your username and password even when they are correct.
Here is what I had to do:
git config --global --unset user.password
Then run your git command (ex. git push) and enter your username.
For the password you need to generate a Personal Access Token.
Go to https://github.com/settings/profile select the Developer Settings on the right. Select Personal Access Token Generate new token. Copy the generated token and use it as the password in terminal.
running git config --global --unset user.password followed by any git command would prompt you to enter username and password.
git config --global --unset user.password
git push (will prompt you for the password)
git status (will not prompt for password again)
In my Windows machine, I tried the solution of #nzrytmn i.e.,
Control Panel>Search Credentials>Select "ManageCredentials">modified new credentials under git option category corresponding to my username.
And then,
Deleted current password:
git config --global --unset user.password
Added new password:
git config --global --add user.password "new_password"
And It worked for me.
If your credentials are stored in the credential helper, the portable way to remove a password persisted for a specific host is to call git credential reject:
$ git credential reject
protocol=https
host=bitbucket.org
⏎
or
$ git credential reject
url=https://bitbucket.org
⏎
After that, to enter your new password, type git fetch.
Given the new token authentification requirement from August 13 2021, this may be what you are looking for:
Generate a new access token
Update the token used to access your repo
git remote remove origin
git remote add origin https://[TOKEN]#github.com/[USER]/[REPO]
git push
There is such a confusion on this question, as there is way too much complexity in this question. First MacOS vs. Win10. Then the different auth mechanisms.
I will start a consolidated answer here and probably need some help, if I do not get help, I will keep working on the answer until it is complete, but that will take time.
Windows 10: |
|-- Run this command. You will be prompted on next push/pull to enter username and password:
| git config --global credential.helper wincred (Thanks to #Andrew Pye)
`
MacOS:
|
|-- 1. Using git config to store username and password:
| git config --global --add user.password
|
|---- 1.1 first time entry
| git config --global --add user.password <new_pass>
|
|---- 1.2 password update
| git config --global --unset user.password
| git config --global --add user.password <new_pass>
|
|-- 2. Using keychain:
| git config --global credential.helper osxkeychain
|
|---- 2.1 first time entry
| Terminal will ask you for the username and password. Just enter it, it will be
| stored in keychain from then on.
|
|---- 2.2 password update
| Open keychain, delete the entry for the repository you are trying to use.
| (git remote -v will show you)
| On next use of git push or something that needs permissions, git will ask for
| the credentials, as it can not find them in the keychain anymore.
`
I was pushing into the repository for the first time. So there was no HEAD defined.
The easiest way would be to:
git push -u origin master
It will then prompt for the password, and once you enter that it will be saved automatically, and you will be able to push.
If you are using github and have enabled 2 factor authentication, you need to enter a Personal access token instead of your password
First reset your password:
git config --global --unset user.password
Then, log to your github account, on the right hand corner, click on Settings, then Developer Settings. Generate a Personal access token. Copy it.
git push
The terminal will prompt you for your username: enter your email address.
At the password prompt, enter the personal access token instead.
do these steps in Terminal:
Delete current password saved in your Mac
git config --global --unset user.password
Add your new password by using this command, replace with your new password:
git config --global --add user.password <new_pass>
you can change password through command line in 2 places, following would edit credentials to connect the repo
git config --edit
The credentials also can be changed at global using global parameter like below
git config --global --add user.password "XXXX"
or set the credentials helper with
git config --global credential.helper wincred
but if you have repo level credentials set the use the first command
git config --edit
For MacOS based on the new rule to use password tokens from August 13 2021.
I tried all other terminal based answers but none worked.
Simply head to Keychain Access
Search for github
Right click on all github related items, including vs-code,
Delete all items
my password was good in github desktop preferences but wrong in the .git/config file
for me the only working solution was to manually edit the file:
.git/config
that contains this line:
url = https://user:password#github.com/user/repo.git
change password to the GOOD password because it was an older one for me
I was able to change my git password by going to Credential Manager in Windows and deleting all the git entries under Windows Credentials πŸ‘’ Generic Credentials.
When doing a git pull or git push, windows will ask for the new user/password itself.
I would try to delete my account in Keychain Access and then run git clone again. Git will ask me for a new password.
on mac BigSur 11.2.3
I updated the credentials in the key chain then I ran the command below.
git credential-osxkeychain erase
host=github.com
protocol=https
I had to do this because no other solution in this thread worked for me after changing to token auth for github. github kept stating repository not found.
If this does not work try to combine this with the other commands for mac in this thread.
Just clone one of your existing repos, this will prompt you for new credentials:
e.g.
git clone https://myuser#bitbucket.org/mypath/myrepo.git
(where https://myuser#bitbucket.org/mypath/myrepo.git is an address of one of your existing repos)
Tried everything but nothing worked. Then the following did work.
Before any of the above steps, lock and unlock the keychain again coz sometimes it sorta gets stuck.
Install the GitHub Desktop β€” it helps.
For those who are looking for how to reset access to the repository. By the example of GitHub. You can change your GitHub profile password and revoke all "Personal access tokens" in "Settings -> Developer settings" of your profile. Also you can optionally wipe all your SSH/PGP keys and OAuth/GitHub apps to be sure that access to the repository is completely blocked. Thus, all the credential managers, on any system will fail at authorisation and prompt you to enter the new credentials.
Following steps can resolve the issue .....
Go to the folder ~/Library/Application Support/SourceTree
Delete the file {Username}#STAuth-bitbucket.org
Restart Sourcetree
Try to fetch, password filed appear, give your new password
Also can run git fetch command in terminal and need to type password
Done
None of the command line options from within terminal worked for me. Ultimately, I just opened up keychain manually, searched for 'git' under 'All Items', found an entry there and deleted it. That did it! Next time I tried a git pull from the terminal and it prompted me for new creds.
For MAC users, using git GUI (Works for Sourcetree, may work for others as well). Would like to add a small remark to Derek's answer. The original suggestion:
$ git config --global --unset user.password
should be followed by a push/pull/fetch BUT it might not work when done from the GUI. The %100 working case would be to do the very first consecutive prompt-triggering git command from console. Here is an example:
Locate to your git repository root directory
Type in $ git config --unset user.password
Proceed with a git commend of your choice in terminal e.g.: $ git push
Then it will ask you to provide the new passoword.
On macOS, e.g. after OSX v.11.6, should go to KeyChain and search "git". And delete the relevant keys. It will work.

Resources