How do I push to GitHub under a different username?

后端 未结 20 1920
盖世英雄少女心
盖世英雄少女心 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:39

    It's simple while cloning please take the git URL with your username.While committing it will ask your new user password.

    Eg:

    git clone https://username@github.com/username/reponame.git

    git clone https://username@bitbucket.org/username/reponame.git

    0 讨论(0)
  • 2020-12-02 04:39

    If you have https://desktop.github.com/
    then you can go to Preferences (or Options) -> Accounts
    and then sign out and sign in.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-02 04:41

    git config user.name only changes the name I commit. I still cannot push. This is how I solved it, and I think is an easy way to me.

    1. Generate a SSH key under the user name you want to push on the computer you will use https://help.github.com/articles/connecting-to-github-with-ssh/

    2. Add this key to the github user account that you want to push to https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

    3. Choose to Clone with SSH

    You can push in as this user to that repo now.

    0 讨论(0)
  • 2020-12-02 04:45

    this, should work: git push origin local-name:remote-name

    Better, for GitLab I use a second "origin", say "origin2":

    git remote add origin2 ...
    then

    git push origin2 master

    The conventional (short) git push should work implicitly as with the 1st "origin"

    0 讨论(0)
  • 2020-12-02 04:47

    The userid where the commit happens is stored in the config file.

    go to the top of the repository vi .git/config

    change the url line listed after "[remote "origin"] to have the appropriate userid

    0 讨论(0)
提交回复
热议问题