Multiple github accounts on the same computer?

后端 未结 25 2572
野的像风
野的像风 2020-11-22 02:56

Trying to work on my both my actual \"work\" repos, and my personal repos on git hub, from my computer.

The work account was set up first, and everything works flawl

25条回答
  •  日久生厌
    2020-11-22 03:35

    You should and must not push to the project with some common credentials. Once starting on a new machine use the following steps to setup and use correctly your gitlab credentials:

    • create the pubic / private ssh keys on the machine
    • copy paste the public key to the gitlab/github ui interface ( anyone hinting how-to do via the cmd line gets a free beer ... )
    • make sure you clone the repo via the git and not http url
    • set the git alias to avoid constant typing of the same prefix to the git command
    • during git commit ALWAYS use the author and e-mail flags
    • use git as normal you would do it

    All this as follows:

     # create the public / private key credentials on that specific machine
     ssh-keygen -t rsa -b 4096 -C "<>@org.net" -f ~/.ssh/id_rsa.<>.`hostname -s`
    
     # setup your public key in the gitlab ui 
     cat ~/.ssh/id_rsa.<>.`hostname -s`
    
     # make sure you clone the repo via the git and not http url
     git clone git@git.in.org.net:org/some-repo.git
    
     # set the git alias to avoid constant typing of the repeating prefix to the git cmd
     alias git='GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.<>.`hostname -s`" git'
    
     # during git commit ALWAYS use the author and e-mail flags
     git add --all ; git commit -nm "$git_msg" --author "YourFirstName YourLastName "
    
     # use git as normal
     git fetch --all; git pull --all 
    

提交回复
热议问题