Fix git push failure

Fix git push failure

Problem

One day, I suddenly found that I can not access to my repo directly using git push command.

I tried check connection using

1
ssh -vT git@github.com

everything went well.

So I think the ssh key may have been specified incorrectly, while directly using git push (I also got other ssh keys for other github repositories, which may conflict).

Solution

  1. generate a new ssh key pair

    1
    ssh-keygen -t ed25519 -C "your_email@example.com"

    and rename it (e.g. id_ed25519_github) to distinguish it from other keys.

  2. change the ssh config

    1
    vi .ssh/config

    to point the right key

    1
    2
    3
    Host github-repo
    HostName github.com
    IdentityFile=/home/dyliu/.ssh/id_ed25519_github
  3. use alternative way to pull or push repo

    1
    git push git@github-repo:yourname/your-repo.git

Reference

https://docs.github.com/en/enterprise-cloud@latest/authentication/connecting-to-github-with-ssh/managing-deploy-keys
https://docs.github.com/en/enterprise-cloud@latest/authentication/connecting-to-github-with-ssh/using-ssh-agent-forwarding


Fix git push failure
https://dyliu0312.github.io/blog.github.io/2025/02/09/Fix-git-push-fail/
Author
dyliu
Posted on
February 9, 2025
Licensed under