[SOLVED] Despite being SSH Authenticated to GitHub, terminal (Bash, PWSH) Git created repo’s will not Push, Fetch remote – but GitHub Desktop created will

Issue

This Content is from Stack Overflow. Question asked by iPoetDev

Despite being SSH Authenticated to GitHub, terminal (Bash, PWSH) Git created repo’s will not Push, Fetch remote – but GitHub Desktop created will.

Date: From 16/09/22 – 18/09/22: Two days of effort.

  • [x] Git (Windows) installed in custom folder Gitx64 under C:Program Files
  • [x] Symlink created from C:Program FilesGitx64 to C:Program FilesGit
  • [x] OpenSSH (Windows) and ssh_config at “`$Home/.ssh/config
  • [x] Git (Windows) Global config and at $Home/.gitconfig

Problem Statement

Note: I have a juicy issue as I have been switching between bash | pwsh for Git and GH CLI and GitHub Desktop and SourceTree trying to diagnose and resolve for 2 days.

For creating, not cloning, a local repo and creating a remote repository from command line/terminal works but interacting with Git Push | Fetch | Pull does not
Thinks that it is not a repository or am not authenticated or have correct rights/identity.

  • I can authenticate to GitHub.com with SSH and a (RSA) Public Key via command line SSH and GH CLI tooling.

  • I can, with git remote add <remote_name> <remote_repo_url>

    • But this does not appear on GitHub.com (i.e., like it is an internal or …?)
  • I can, with GitHub CLI, creates a remote repo successfully (see below)

    • But GitHub CLI does not want to add a remote at <remote_repo_url>
  • GitHub Desktop throws either

    • Not authenticated error (see screenshot with annotations)

    GitHub Desktop Auth error, ++Annotations

  • Bash: git push or fetch generates the following error

$ git fetch
fatal: 'git@github.com/iPoetDev/Gobals1.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

If it is TL/DR, pm me or I will follow up with a Loom link to visualise in further detail. I will also see if I can get this as an Issue on my GitHub (via a functional repo) as an issue for off Stack Overflow concern.

Git Global Config

  • Not using system file
  • Not using per repo (Can if I need to)
  • Not using (yet) command line configurations

Config Directives

Selected Directives from Global Config at $Home/.gitconfig

[user]
    name = <GitHub Name>
    email = <GitHub secondary email address in use>
    # Options: 1: 51715025+iPoetDev@users.noreply.github.com
    # Options: 2: <GitHub primary email address in use>
[core]
    # Commented Out
    # sshCommand = ssh -i ~/.ssh/id_rsa -F /dev/null

[init]
    defaultBranch = main
[push]
    default = current
    # removes git push -u
    autoSetupRemote = true 
[credential "helperselector"]
    selected = manager-core
[credential "https://github.com"]
    #username = git
    username = iPoetDev
    helper = 
    helper = D:\.Tools\.scoop\apps\gh\current\bin\gh.exe auth git-credential

#   As explained, Git only allows you to access repositories owned by yourself, i.e. the user who is running Git, by default.
[safe]
     directory = D:/Code/Gobals/* 
     directory = D:/Code/Gobals/Gobals
     directory = D:/Code/Gobals/Gobals1

GitHub CLI && Repo Management

Authenticates with GitHub CLI (Interactively)

  • No PAT Token, but have one ready
  • Switches from https to ssh for authentication
 gh auth login
? What account do you want to log into? GitHub.com
? You're already logged into github.com. Do you want to re-authenticate? Yes   
? What is your preferred protocol for Git operations? SSH
? Upload your SSH public key to your GitHub account? $Homez.sshid_rsa.pub  
? Title for your SSH key: ```<Added Title>```
? How would you like to authenticate ```<Added Title>```? Login with a web browser

! First copy your one-time code: ```<One Time Code>```
Press Enter to open github.com in your browser... 
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
HTTP 422: Validation Failed (https://api.github.com/user/keys)
key is already in use

Creates a Remote on GitHub.com

  • Output: D:CodeGobalGobals1Gobals1 is not a git repository. Run git -C "Gobals1" … (again)
  • cd .. for /d/Code/Gobals1 -> /d/Code/Gobal && git -C Gobals1 init
  • Reinitialized existing Git repository in D:/Code/Gobal/Gobals1/.git/
  • At /d/Code/Gobal, noticing I am not in Gobals 1, due to gh quirk of running from ParentDir
    • Enters: gh repo create --private -d Gobals1 --remote Gobals1 --source Gobals1 --homepage github.com/iPoetsDev/Gobals1.git
    • ✓ Created repository iPoetDev/Gobals1 on GitHub
    • X Unable to add remote "Gobals1"
    • Eyeballed Repo on GitHub.com, default branch ‘main`



Solution

You’re trying to push to a remote repo that doesn’t exist. That’s all there is to it, and it has nothing to do with the details of your local configuration. To create a repo on GitHub you can go to https://github.com/new (log in if necessary) and fill in the requested information. Once it’s created, you can push to it. Other hosts are, of course, different.


This Question was asked in StackOverflow by iPoetDev and Answered by hobbs It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?