2

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.

This post is subject to future edits and refinements as questions arise

Pre-requisites: Local

  • [x] Git (Windows) installed in custom folder Gitx64 under C:\Program Files
  • [x] Symlink created from C:\Program Files\Gitx64 to C:\Program Files\Git
  • [x] OpenSSH (Windows) and ssh_config at $Home/.ssh/config
  • [x] Git (Windows) Global config and at $Home/.gitconfig
  • [x] ssh-agent (Windows) is on automatic start.
  • [x] ssh-add -L checks for loaded keys.
    • [x] ~/.ssh/id_rsa key is loaded as off 18/09/2022
  • [x] Focusing on ~/.gitconfig (Global user)
  • [NO] As yet, not using system git/config.

Pre-requisites Terminal Profiles

.bash_profiles / .bashrc
  • [ ] No terminal checking, , onload, for ssh-agent (yet, removed for reset of troubleshooting)

  • [] No terminal checking, onload, for ssh-add (yet, removed for reset of troubleshooting)

  • [?] To be added or incorporated, have some shell scripts

  • [] Removed, so to check if there was a way to not add passphrase in at start of the shell .

  • [] Maybe that is what is missing: the passphrase authentication to the shell??

Powershell $Profiles

Pre-requisites: Remote

  • [x] GitHub.com Account: User: iPoetDev
  • [x] SSH Key added (16/09/22)
  • [x] Interactive, via browser, authentication
    • [x] Via Going to www.github.com
    • [x] GitHub CLI interactive gh auth login
  • [x] PAT Token configured
  • [x] Can Create Remotely and clone locally
  • [x] Remote Repo does exits on GitHub.com (Challenged 19/09)

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:

    • Not authenticated error (see screenshot with annotations) [GitHub Desktop Auth error, ++Annotations][1]
  • 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.

    $ git push 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.

And yet

$ git remote get-url mains 
->
git@github.com/iPoetDev/Gobals1.git

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

NOTE

  • Added in for background and further information.

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? $Home\z.ssh\id_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
    

Authenticates with GitHub CLI (Interactively)

Note: To be updated. Clipping lost in translation and write up. Come back later, when the post is updated. Need to replay and reproduce remote git repo creation by GH CLI.

==========

Possible Components To follow Up

Adding SSH Agent start in .bash_profile (A suggested option)

Add the following snippet to ~/.bash_profile to automaticall start ssh agent so you don't have to reauth git with every remote command.

  • Source - Credit: RayWongJR@Github.com

    # ssh agent
    # -------------------
    SSH_ENV=$HOME/.ssh/environment
    
    function start_agent {
        echo "Initializing new SSH agent..."
        # spawn ssh-agent
        /user/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
        echo succeeded
        chmod 600 "${SSH_ENV}"
        . "${SSH_ENV}" > /dev/null
        /usr/bin/ssh-add
    }
    
    if [ -f "${SSH_ENV}" ]; then
        . "${SSH_ENV}" > /dev/null
        ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
            start_agent;
        }
    else
        start_agent;
    fi
    

Solution Options | Remedies?

Goal Aim is to have secured ssh traffic between all local and remotes, regardless of interaction.

Objective 1 To be able to switch between GUI and Terminal, inc GitHub Desktop, SourceTree and VCode, GitBash, Powershell, without issue.

Objective 2 Not to use two+ valuable days on one issue and end up in negative cost-benefit for other concerns.

Objective 3 Was to Learn about advanced SSH, GitHub CLI, Git-Bash Git usage and finalise baseline Dev Env configuration with VSCode.

OPTIONS
  1. Check if SSH Authentication (Host Key Verification) passes for git@github.com:iPoetDev/Gobals1.git
  2. Change SSH Key Type from RSA to ECDSA
  3. Test for GitLab and/or Bitbucket if issue is replicated for each or is GitHub specific.
  4. Solution unknown and offered here below
  5. Log an issue with GitHub.com or Git or ...??

and not least

  1. Switch back to HTTPS authentication and repeat tests.

Extras

References

  • Added as needed
SSH Config (Selected View)
Host github.com
Hostname github.com 
AddKeysToAgent=yes
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly=yes 
PubkeyAuthentication=yes
Files && Locations
iPoetDev
  • 41
  • 8
  • This 1st post was a heavy lift as getting used to SO own listing and code checking was a pain. Go easy on 1st post. – iPoetDev Sep 18 '22 at 12:14
  • Did you start `ssh-agent` and load the keys using `ssh-add` in your terminal? – kometen Sep 18 '22 at 12:21
  • - ✅ ssh-agent is on automatic start (windows) - ❓ Don't (yet) check ssh-agent && ssh-add in `.bash_profile`, `.bashrc` - Have some samples shell script for ssh-agent and ssh-add for these profiles for Git-Bash/bash shells. - ✅ ssh-agent -L checks for the loaded key and the id_rsa key in question is loaded. And SSH Config File has the AddKeysToAgent=yes – iPoetDev Sep 18 '22 at 12:58

2 Answers2

1

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.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • To add a bit to that, you (iPoetDev that is) said "`git remote add ` ... it is an internal or ...?": Not sure exactly what you mean by the word "internal", but depending on what you mean, probably, yes. :-) The `git remote add` operation adds a *string* to your `.git/config` file in your local repository. This doesn't reach out to GitHub at all. – torek Sep 18 '22 at 23:23
  • Yes, the remote repo does exist. Thorught the editing of this post and troubleshooting of posting, I missed a clipping. Will come back later on this. I lost the code output so have to duplicate and reply. To answer @torek, there are three kinds of repo: public, private and internals (, as per documentation on Github, ...methinks I seen this) for which I assumed it was a form on github.com, but may refer to local). Behaviour: posting a remote by git remote to create remote one from cmd line, would not appear on GitHub.com. – iPoetDev Sep 19 '22 at 15:58
  • I know I can so to Github.com and create a remote repo. I do not want to , I want to create a remote from the command line. As per many guides, this should be possible with `git remote add` command... Weird behaviour ===>> I can create a local repo and can add it remotely (no error) but do not get push or fetch via git commands. I can add a locale repo and publish and push via GitHub Desktop. I seek parity between git command and Github Desktop – iPoetDev Sep 19 '22 at 16:01
  • Suspect it is an ssh identity challenge fail as I am not getting passphrase prompt in shell for PrivKey-PubKey per command line ... and am being refused .... (bash and remote authentication is happening under GH auth cli but not under git commands...) I would have thought one shell two methods share same authentication ... or is this per repo? – iPoetDev Sep 19 '22 at 16:05
  • @iPoetDev that's not how it works. You can't create a remote repo using the `git` command. – hobbs Sep 19 '22 at 16:08
  • Hmmm, so please tell Atlassian and other guide of how to on the web. 1) So you can create a local repo, fresh from scratch and push it remotely by publishing on GitHub Desktop but can not on Git command line. Note: I have done the GUI option with GitHub Desktop and with GH CLI. But you can not create remote git repos via git command? Did I understand you right? If you are, what is `your best method, please`? – iPoetDev Sep 19 '22 at 16:27
  • The first issue above all, is below in part 2, it is authentication, before and as git commands are being used. That is what. Now what and now what again, how to resolve. see below. – iPoetDev Sep 19 '22 at 17:06
  • @iPoetDev: aha, no, that GitHub use of "internal" is an *entirely different thing*. It applies to "enterprise accounts" only, not to ordinary GitHub user accounts. It's kind of a poor name: it should probably be called an "enterprise repository" to match the "enterprise account" and "enterprise managed users" features. – torek Sep 19 '22 at 17:52
1

Folks, visibility is key, and I found it in the log view Output of VSCode Output for the git. I supercharged VSCode with as many extension I could last night and went looking.

Methinks GitHub CLI and git.exe via ~/.gitconfig are not playing ball.

In my git config, see it is useful, I have my credential.helpers configured. Optimally I seek to use either windows credential manager or GitHub link into it, via their official CLI, which is user friendly.

The analayis here is that GitHub Desktop is configured to use the Windows Credential Manager, by default; and git.exe is not but does install with the newest windows credential manager. So having GH.exe take over and be error prone is a blocker. I can revert to simpler config and test.

Nice to have: Prefer GH CLI, but must have: seamless authentication bu ssh and windows's credential helper. No, not the cache or store or local or plantext

git.exe is the calling program and the VSCode output is the log viewer for git.exe.

[2022-09-19T16:36:33.903Z] D:\.Tools\.scoop\apps\gh\current\bin\gh.exe auth git-credential get: line 1: D:.Tools.scoopappsghcurrentbingh.exe: command not found
D:\.Tools\.scoop\apps\gh\current\bin\gh.exe auth git-credential erase: line 1: D:.Tools.scoopappsghcurrentbingh.exe: command not found

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

D:\.Tools\.scoop\apps\gh\current\bin\gh.exe auth git-credential get: line 1: D:.Tools.scoopappsghcurrentbingh.exe: command not found
__\_____\_____\___\__\______\___\__.exe

Part 2 of the Problem Statement (same issue: authentication)

Something is stripping out the path separators and my authentication is failing per repo on the command line.

But who is the culprit. BTW I did not manually add the gh.exe to the git config, it was automatically done at install and first run, I think.

Solve for this and solve for git remote add, (above) I think...

Secondly, I have credential.user = iPoetDev, should I switch this over to credential.user = git for ssh, given all ssh is anonymous via git@github.com/iPoetDev

VSCode Output

iPoetDev
  • 41
  • 8
  • The GitHub cli (`gh`) is not *meant* to play with `.git/config`, and vice versa: GitHub is a 2010 thing, Git is a 2005 thing. GitHub is a money-making company (now part of Microsoft) that built on Linus Torvalds' free Git software by providing add-ons. `gh` is for working with GitHub, `git` is for working with Git. Note that GitHub Desktop attempts to straddle the fence: it knows both Git *and* GitHub (and as such, is useful, but is a bit like a mechanic who can only work on Uber vehicles: don't try to use him on your own car). – torek Sep 19 '22 at 17:54
  • As for `credential.user`: this may or may not be used by any given credential helper (each credential helper is its own program and can do whatever it wants), but it's *completely ignored* by ssh, which is not a Git program and predates Git by another decade. Ssh has its own setup and mechanisms. When you use ssh with GitHub, GitHub demand that you log in as user `git`. (The credential helpers are for https only.) – torek Sep 19 '22 at 17:56
  • For questions about the `gh` CLI, ask a new question with the [tag:github-cli] tag. I suspect, however, that it's using the Unix-style "backslash is a quote character" convention: if you want to give it a path like `D:\foo\bar` you can spell it `D:/foo/bar` or `D:\\foo\\bar`. The initial implementation of `gh` was probably on Linux. – torek Sep 19 '22 at 17:57
  • I appreciate the atomicity of the questions' purpose. And yes, GitHub CLI is part of the initial problem statement, initially, but I dropped it by accident. However, I used all parts in my troubleshooting, so separation of concerns is not the intent. – iPoetDev Sep 19 '22 at 19:56
  • Yes, yes, a philosophical opinion on the bigger entities is informative, but not so useful. ....... bar the first statement. However, when I have the time, I will log this as an issue on the GitHub CLI repo. _||||_ FOR nows: ||| 1) I will decouple the `gh` CLI from the `~/.gitconfig` in the `credential.helper`. ||| 2) I am using ```D:\\foo\\bar\\``` in the gitconfig. So I will tweek and tailor for etc, ... ||| 3) I will switch over to git for the `credential.helper` and see for self., but interesting that it is completely ignored by ssh,. – iPoetDev Sep 19 '22 at 20:05
  • Good point on the car mechanic metaphor :) – iPoetDev Sep 19 '22 at 20:08
  • @torek, i see this https://stackoverflow.com/questions/72209373/github-cli-command-not-found and your comments. Useful. – iPoetDev Sep 19 '22 at 20:16