0

I am trying to clone, add some code to and commit the code to my private repository on Github. The issue is that whenever I do

git clone https://github.com/my-username/my-Repo.git

I get

remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/.../my_repo.git/'

I didn't have this issue before executing the following command

git credential-osxkeychain erase

Before executing above command I managed to clone the repo by using my personal access token, managed to execute git init, git add blah.py and git push without any issues but nothing showed up on my github page.

Now, after removing the credentials from my keychain, when I enter the CORRECT username and password when cloning my private Github repository I get the remote: Invalid username or password. error. I've both manually written my username and password into the terminal and copied from saved logins on firefox, neither works and I know the username and password is correct since I can easily login to my Github account on github.com with the same information I enter into the terminal when attempting to clone my repo. Using the e-mail does not change the "invalid ..." error.

tl;dr How do you control a private repository on macosx via terminal?

Edit: I use 2FA

py_enc
  • 11
  • 4

3 Answers3

0

Because you're using 2FA, you actually won't use your password but instead you'll use an access token that you can create on the GitHub website.

Here's instructions on how to do that.

Then for your clones / pushes / etc, use:

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

More info can be seen in the answers to this [very related question].(2FA give problems when pushing to GitHub)

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Using my token as password worked when cloning, however when I do `git push` I get no prompt about username or password, it only says that everything is up to date, which it isn't since it didn't push the change! – py_enc Jun 29 '19 at 12:15
  • Did you "git add" any files you changed? – Michael Dautermann Jun 29 '19 at 12:18
  • `touch blah.py` then I did `git add blah.py` then `git push` and `git commit -a -v` and finished with `git push` again. Nothing on my git page but command says everything is up to date. – py_enc Jun 29 '19 at 12:30
  • Which branch are you in? What happens when you try "git push origin master"? – Michael Dautermann Jun 29 '19 at 12:35
  • `git push origin master`results in `Everything up-to-date`. I am in my /Users/name/Git-Projects/my_project/. Doing `git init`results in `Reinitialized existing Git repository in /Users/name/Git-Projects/my_project/.git/` – py_enc Jun 29 '19 at 12:42
  • All the "git init" you are doing can't be good for your repo. Try doing a fresh clone from git into a different location on your local drive, then copy in and add/commit/push from there. I suspect you'll have better results. – Michael Dautermann Jun 29 '19 at 12:56
0

Fixed the issue by doing the following

1. signed in with my auth token
2. generating a ssh-key and adding it to my agent
3. adding the ssh-key to my github
4. cloning the repo in a different directory and skipping 'git init'
py_enc
  • 11
  • 4
0

Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.

For example, on the command line you would enter the following:

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token
hakki
  • 6,181
  • 6
  • 62
  • 106