20

I'm just getting started with Git/Github and I'm completely stuck. I'm using Terminal on Mac/OSX El Capitan and when it asks for password it tells me it is invalid, but I am entering the same password that I created for my GitHub account, so surely this should work? What am I doing wrong?

Last login: Sun Dec  4 10:46:35 on ttys000
Seans-MBP:~ mrseanbaines$ git push -u origin master
Username for 'https://github.com': mrseanbaines
Password for 'https://mrseanbaines@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/mrseanbaines/cartwheeling-kitten.git/'
Seans-MBP:~ mrseanbaines$
Forge
  • 6,538
  • 6
  • 44
  • 64
mrseanbaines
  • 823
  • 2
  • 12
  • 25

7 Answers7

39

I had faced same issue.
Solution:
Step 1: Control Panel
Step 2: Credential Manager
Step 3: Click Window Credentials
Step 4: In Generic Credential section ,there would be git url, edit and update username and password Step 5: Restart Git Bash and try for clone enter image description here

amoljdv06
  • 2,646
  • 1
  • 13
  • 18
31

Once you have enabled 2 Factor Authentication (2FA) on GitHub, you cannot use your GitHub password on the command line. Instead, you have to use a personal access token.

Personal access tokens are used to authenticate you for personal applications and on the command line. The command line does not tell us we need to generate a personal access token, which is why this solution is often overlooked by programmers.

Navigate to the “Settings” page Click “Developer settings” in the sidebar Click “Personal access tokens” in the sidebar Click “Generate new token” Fill in the form to create a new token

Use that token as password and git clone will work work

KamyFC
  • 858
  • 9
  • 17
  • +1 for the above solution. After following the above steps original issue got fixed, but I had to go to Github and click on "Enable SSO" there we see "Authorize" button after I click that and later `git config --global credential.helper store` this helped to fix the annoying repetitively asking username in command line often – ravibeli Jul 19 '21 at 12:59
10

(1) Go to https://github.com/settings/security , turn off Two-factor authentication.

(2) Create a new folder, inside the new folder:

git clone https://github.com/mrseanbaines/cartwheeling-kitten.git
cd cartwheeling-kitten

Open empty source code directory, since you use macOS, type

open .

(3) Copy your source code to folder cartwheeling-kitten (it's the opening folder)

(4) Config

git config user.name "Your full name"
git config user.email "Your_email_address_what_used_to_register Github_account"

(5) Add remote URL

git remote add upstream https://github.com/mrseanbaines/cartwheeling-kitten.git

(6) Add to stage, then push

git add -A .
git commit -m "Upload source code"
git push -u origin master

(7) Go to https://github.com/mrseanbaines/cartwheeling-kitten see result.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • I followed your instructions, but after the 'git push -u origin master' it asks me for username and password. Looks like this: https://snag.gy/cqNOts.jpg ...and the GitHub page still looks like this: https://snag.gy/nhKacb.jpg After I enter the password it goes to the next line without the "Seans-MBP:" and nothing seems to happen, but if I try to close the terminal, it seems as though it is in the middle of doing something. Looks like this: https://snag.gy/t1q9lv.jpg – mrseanbaines Dec 04 '16 at 19:26
5

2020 - When you change your password on Github and after in your local machine it will complain about credentials but you can easily fix it doing a git pull which will force asking you the credentials. So you type the new one and be happy :).

Fábio BC Souza
  • 1,170
  • 19
  • 22
1

If you already have setup SSH key in your system for some other git account then just do these steps https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

and check activation using ssh -T git@github.com if you see 'Hi GitAccountUserName! You've successfully authenticated, but GitHub does not provide shell access.'

Then continue your previous work.

Uday Sravan K
  • 1,305
  • 12
  • 18
0

Make sure your remote urls are correct. It looks like you're missing the protocol, it should be: https://github.com/mrseanbaines/cartwheeling-kitten.git. You can verify this by cloning the repo to another directory, and trying git operations there.

If you want to fix it to add the protocol, you can do: git remote set-url origin https://github.com/mrseanbaines/cartwheeling-kitten.git

yelsayed
  • 5,236
  • 3
  • 27
  • 38
0

When I tried to push the code into remote repo from local (macbook), I faced the same issue after PASSWORD reset on GHE website.

$ git push -u origin coffee_shop_autorization

remote: Invalid username or password.

fatal: Authentication failed for 'https://github.com/ravinderreddy-p/FSND.git/'

Then I followed below simple steps to fix this issue:

  1. I cloned another repository from GHE to local in different folder:

    git clone https://github.com/ravinderreddy-p/bookshelf.git

  2. I switched to this folder by 'cd bookshelf'
  3. I tried to push the same without making any changes as below:

    git push

  4. It prompted for Username for 'https://github.com':<Provide your GHE user name> then press enter.
  5. It prompted as Password for 'https://ravinderreddy-p@github.com': <provide updated password on GHE> then press enter
  6. You will see this message as "Everything up-to-date"

All Done.

Now go to your previous local repo where you tried to push the code into remote and execute your previous command

git push -u origin coffee_shop_autorization

It will push the code into remote repo and you can see similar as below (with your repo and branch details):

Enumerating objects: 35, done.

Counting objects: 100% (27/27), done.

Delta compression using up to 4 threads

Compressing objects: 100% (14/14), done.

Writing objects: 100% (15/15), 2.47 KiB | 843.00 KiB/s, done.

Total 15 (delta 8), reused 0 (delta 0)

remote: Resolving deltas: 100% (8/8), completed with 5 local objects.

remote:

remote: Create a pull request for 'coffee_shop_autorization' on GitHub by visiting:

remote: https://github.com/ravinderreddy-p/FSND/pull/new/coffee_shop_autorization

remote:

To https://github.com/ravinderreddy-p/FSND.git

  • [new branch] coffee_shop_autorization -> coffee_shop_autorization Branch 'coffee_shop_autorization' set up to track remote branch 'coffee_shop_autorization' from 'origin'.
Ravi Pullagurla
  • 466
  • 4
  • 10