How do I push to GitHub under a different username?

后端 未结 20 2036
盖世英雄少女心
盖世英雄少女心 2020-12-02 04:00

A friend and myself are sharing my computer. I\'ve made pushes to GitHub using the git bash shell on Windows 7. Now we\'re in a different project on that computer and I need

20条回答
  •  被撕碎了的回忆
    2020-12-02 04:41

    I setup an ssh alias using a custom IdentityFile and rewrote the origin to use my custom me-github hostname.

    #when prompted enter `id_rsa_user1` as filename
    ssh-keygen -t rsa
    
    # ~/.ssh/config
    Host user1-github
    HostName github.com
    Port 22
    User git
    IdentityFile ~/.ssh/id_rsa_user1
    
    #check original remote origin url
    git remote -v
    origin git@github.com:user1/my-repo.git
    
    #change it to use your custom `user1-github` hostname
    git remote rm origin
    git remote add origin git@user1-github:user1/my-repo.git
    

提交回复
热议问题