Github – I switched accounts and now I can't push because I have the wrong username

So I’m now “jononomo” on github. A year ago, however, I was “zononomo”. I quit software for a while and bought a new laptop in the interim. Then I came back and created a new account on Github under the handle “jononomo” and now I’m trying to sync my dotfiles between my two laptops. From my new laptop I created a git repository and pushed it up to github where it can be viewed under the “jononomo” account. Then I went to my old laptop and cloned this repository. Everything worked as expected.

Then I made some changes to my dotfiles on my old laptop and now I’d like to push these changes to github so that I can then pull them down to my new laptop. The problem is that when I run the command:

  • PhpStorm. Two GitHub projects handled with different GitHub accounts
  • How to safely change github account name?
  • GitHub username change (with noreply as email for commits)
  • Will changing my Github username to SnakeCase break anything?
  • Github wrong username
  • Bitbucket different keys and accounts
  • git push origin master
    

    I get the error message:

    ERROR: Permission to jononomo/.dotfiles.git denied to zononomo.
    

    The first thing I did was blow away my old SSH keys in ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub. Then I generated new SSH keys and added my new public key to my jononomo github account. But that didn’t fix the problem. If I run the command:

    ssh -T git@github.com
    

    I get the response:

    Hi zononomo! You've successfully authenticated, but GitHub does not provide shell access.
    

    Next, I followed the solution given here: https://stackoverflow.com/a/8152291/1701170 This person suggested that I create a ~/.ssh/config file with the following contents:

    Host github-jononomo
        User git
        Hostname github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_dsa.pub
    

    and then he suggested I run the command:

    git remote set-url origin git@github-jononomo:jononomo/.dotfiles.git
    

    I tried that, but it didn’t fix my issue. I’m still getting the message:

    ERROR: Permission to jononomo/.dotfiles.git denied to zononomo.
    

    Incidentally, my .gitconfig has the following contents:

    [user]
        name = Jon Crowell
        email = me@myemail.com
    [github]
        user = jononomo
        token = 2a18a7235746324aefec34b234aa343a
        email = me@myemail.com
    [credential]
        helper = osxkeychain
    

  • Git rebase when previous commit changed
  • Error: Failed to update the AWS Elastic Beanstalk environment
  • How to config gitignore?
  • How to use git rebase properly?
  • Fixing a big mistake on heroku
  • How to I “move” my commits from “no branch” to an actual branch?
  • 2 Solutions collect form web for “Github – I switched accounts and now I can't push because I have the wrong username”

    zononomo? GitHub shouldn’t recognize you as zononomo anymore.
    Maybe you have an ssh agent delivering your old key?

    As suggested in “Having Trouble Switching Github accounts on terminal”, add the line:

     IdentitiesOnly yes
    

    to your config file and see if GitHub is still using that old id.

    however I’m still getting the

     ssh: Could not resolve hostname github: nodename nor servname provided, or not known error
    

    The “hostname” to resolve must match the Host entry of the config file.

    If that Host entry is github-jononomo, you must use it in your ssh address as well:

    git remote set-url origin github-jononomo:jononomo/.dotfiles.git
    

    I got it to work by taking the following steps:

    First my ~/.ssh/config file is as follows:

    Host github-jononomo
        HostName github.com
        User git
        IdentityFile  ~/.ssh/id_rsa
        IdentitiesOnly yes
    

    Second, I ran the command git remote set-url origin git@github-jononomo:jononomo/.dotfiles.git

    Third, I ran the command ssh -T git@github.com and got the result Hi jononomo! You've successfully authenticated, but GitHub does not provide shell access.

    Fourth, I logged in to my old github account, removed the SSH key and completely deleted the account.

    Many thanks to VonC.

    Git Baby is a git and github fan, let's start git clone.