14

This might be stupid question. But I could't find anything about this by search. Maybe, this is stupid question.

I've stored my codes in github.

2 hours ago, I want update my codes in repository, but my local doesn't have that code. So I cloned it, modified codes, and pushed it. At this time, git prompt me to type user name of github and password. I typed it and code updated.

After that, I read my codes in "OTHER" repository. And I found something needed to modify, too. So I cloned that repository to my local computer, modified codes, and pushed it.

But... at this time, git does not prompt message to input user name and password of github.

Huh? Is this mean that anyone cloned my codes in github could also push to my github repository? This is very dangerous situation, isn't it?

So I tested with creating new repository in github. I cloned this new repository to my local, made some change, and pushed it. But git does not prompt message to type user name and password, too.

So, my question is,

  1. Does the first pushing save github login information in my local computer, and use it after other push? Then, where it is?
  2. What is the github repository's default security setting? I didn't register SSH key of this local computer to github account. It seems irrational to anyone push to my repository with master branch, without any requirement of authentication.

Below is my commands when doing above works.

$git init
$git clone https://github.com/[user name]/[repository name].git
<some change>
$git add *
$git commit -m "change"
$git remote add origin https://github.com/[user name]/[repository name].git
$git push origin master

Added information. For more details, I captured my github setting pages.

enter image description here

enter image description here

enter image description here

casamia
  • 619
  • 1
  • 10
  • 19

6 Answers6

32

You can manually unset credential.helper by running below command.

git config --global --unset credential.helper

use --global or --local or --system as per your needs.

Then pushing in github will ask for username and password.

If you are on windows one other way to do this is as below but note that it will again save your credentials if you use credential.helper with git.

Go to control panel -> Credential Manager -> Windows Credentials and remove your git credential entry/entries. enter image description here

Foolish
  • 3,952
  • 33
  • 46
  • No.. This doesn't work. I changed `--global` options to `--local` and `--system`, but still not asking. – casamia Aug 03 '15 at 18:31
  • 2
    thats a great answer. This solves issues when one have multiple git accounts. – explorer Sep 22 '17 at 16:45
  • 1
    I am using windows. The first part of the answer didn't help(I tried only with --local). The second part i.e. deleting the entry from Credential Manager did the trick for me. Thanks a lot. – Saurabh Misra May 17 '19 at 04:35
5

This might help.. https://help.github.com/articles/caching-your-github-password-in-git/

Git by default saves your passwd in cache for 15 min.

Maelstrom
  • 443
  • 2
  • 9
  • 1
    Ah.... Your link is right! I launched osx's keychain utility and found my github keychain has created. When I delete this keychain, the `$git push origin master` command asked me to input username and password! Thanks a lot! – casamia Aug 04 '15 at 01:08
  • Happy to have helped! – Maelstrom Aug 04 '15 at 04:25
  • I went a long way to find *how to really use* the keychain utility, here is the link for someone who might have the same problem: https://help.github.com/articles/updating-credentials-from-the-osx-keychain/ – JJPandari Jan 26 '18 at 06:37
3

For Mac users password can be clear by running below command :

git credential-osxkeychain erase
host=github.com
protocol=https
ireshika piyumalie
  • 2,226
  • 22
  • 22
1

Problem: When pushing to the remote git will report: remote: Permission to [your/repo] denied to user [bob]

The username in the store may be wrong. Powershell this:

cd c:\Program Files\Git\mingw64\libexec\git-core;

git-credential-manager.exe remove [bob];

git push origin [your branch];

you should now be prompted for credentials.

Shaun
  • 11
  • 2
0

In Linux check

cat /home/<MyUser>/.git-credentials
DimiDak
  • 4,820
  • 2
  • 26
  • 32
-3

As fas as I understand, there are several ways to checkout using git.

Specifically, using http protocol (that uses name/password) and using ssh (that uses ssh public/private key pair)

It seems you are using ssh, so private/public key pair is used for authorization

Georgy Buranov
  • 1,296
  • 1
  • 16
  • 26
  • 1
    When he lists his commands, you can see that he is using the https protocol. If you clone the repo using the `https` protocol in the url (`$git clone https://github.com/[user name]/[repository name].git`) or you add the remote with `https` (`$git remote add origin https://github.com/[user name]/[repository name].git`), it will use `https`. For it to use `ssh`, you need to use the url with `ssh://` in front. Also, he shows that he did not add any ssh keys to github. So it is impossible for github to use ssh authorization (public/private key pair) even if that was the protocol he tried to use. – Irmak Sirer Nov 09 '16 at 21:13