Guide: Github Troubleshooting - dsriseah/ursys GitHub Wiki

This is an annoyance that will strike everyone who is relatively new to using git to pull and push to a repository when there are multiple Github identities involved. This is poorly documented, so here's my cheat sheet.




Problem: Can't Push Code to New Repo with SSH

After creating the repo on Github, you can then push your existing code. image

You've got two options for connecting the Github upstream repo to your local git repo.

  1. HTTPS username/password used for https remote repo urls (e.g. https://github.com/dsriseah/ursys.git)
  2. SSH used for github remote repo urls (e.g. [email protected]:dsriseah/ursys.git)

In the example above, I've chose SSH, so the instructions read:

git remote add origin [email protected]:dsriseah/example.git
git branch -M main
git push -u origin main

However, this is probably wrong if you are using multiple logins for Github.

Explanation

While the first line git remote add origin [email protected]:dsriseah/example.git looks like you're specifying a user [email protected] with an account dsriseah, it's actually this:

[email protected]:dsriseah/ursys.git
    ---------- -------- -----
    host_ident username repo

The git@ is always the same, as there is a single user on Github that's responsible for the API. The rest of the string specifies:

  • host_ident - the name of an SSH Host identifier in ~/.ssh/config, which is an arbitrary string
  • username - this is the Github account name
  • repo - the repo under the user's account

SSH Hosts start identity blocks that look like this:

Host github.com
  HostName github.com
  User git
  PubkeyAuthentication yes
  IdentityFile ~/.ssh/ident_rsa
  ... etc

"Host" is an arbitrary string name, whereas "HostName" is the actual domain name. This is a misleading convention that confuses newcomers to SSH as both strings look identical.

If you have multiple GitHub accounts, you will have different SSH identities for each account. Typically you will generate an SSH key pair and upload the public key half to your account, as detailed here.

For example, here is what two different SSH identities might look like in your ~/.git/config:

# --- Sourcetree Generated ---
Host github.com
  HostName github.com
  User git
  PubkeyAuthentication yes
  IdentityFile ~/.ssh/ident_rsa
  ... etc ...

# --- created manually ---
Host github-personal
  HostName github.com
  User git
  PubkeyAuthentication yes
  IdentityFile ~/.ssh/personal_rsa
  ... credentials ...

There are two SSH Hosts defined, github.com and github-personal. To set correct key for git operations, we need to specify the correct SSH host in the string. So, if I've cloned dsriseah/example which is using the github-personal identity, my connection string should be:

git remote add origin git@github-personal:dsriseah/example.git

not

git remote add origin [email protected]:dsriseah/example.git

If you need to fix the settings for the repo itself, you can find the url in .git/config and edit it directly.




Problem: Can't Clone Repo via SSH

This is the mirror to the above problem. The default clone instructions look like:

git clone [email protected]:dsriseah/example.git

Which means it's using the identity github.com is defined in my ~/.ssh/config file as the identity for a completely different user. The identity that corresponds to my github.com/dsriseah account is defined as github-dsriaseah, so the correct url is:

git clone git@github-dsriseah:dsriseah/ppmp-ssg.git

HOWEVER:

If you don't have a Github account, you have to use the https link instead. This is good for read-only access. You could also use this form if you do have a Github account, but you'll have to enter your username/password on any write operation to the repo. You can try to use git credential helpers to cache that stuff for you.




Problem: Pushes Rejected due to Missing or Private Email Error

If you bounce between Visual Studio Code's Git features and another Git client, you may see this error when attempting to push:

remote: error: GH007: Your push would publish a private email address.

This doesn't seem to always be a hard error, and it isn't always passed along. Github is returning this error if it detects a "private" email address associated with your account, as all commits can have this information in it.

Solution

You are damned if you have an email address and username and damned if you don't. The easiest workaround it to set it to Github's generated commit email address address for privacy. You could also turn the feature off, but I like to know if I am leaking private data.

In your local repo's .git/config file, add the generated commit email address that you can find on your Account Settings page. For example:

[user]
  name = dsriseah
  email = [email protected] 
⚠️ **GitHub.com Fallback** ⚠️