Multiple github accounts on the same computer?

后端 未结 25 2285
野的像风
野的像风 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:34

    I use shell scripts to switch me to whatever account I want to be "active". Essentially you start from a fresh start, get one account configured properly and working, then move the these files to a name with the proper prefix. From then on you can use the command "github", or "gitxyz" to switch:

    # my github script
    cd ~/.ssh
    
    if [ -f git_dhoerl -a -f git_dhoerl.pub -a -f config_dhoerl ]
    then
        ; 
    else 
        echo "Error: missing new files"
        exit 1
    fi 
    
    # Save a copy in /tmp, just in case
    cp id_rsa /tmp
    cp id_rsa.pub /tmp
    cp config /tmp
    echo "Saved old files in /tmp, just in case"
    
    rm id_rsa
    rm id_rsa.pub
    rm config
    echo "Removed current links/files"
    
    ln git_dhoerl id_rsa
    ln git_dhoerl.pub id_rsa.pub
    ln config_dhoerl config
    
    git config --global user.email "dhoerl@.com"
    git config --global github.user "dhoerl"        
    git config --global github.token "whatever_it_is"
    
    ssh-add -D
    

    I've had great luck with this. I also created a run script in Xcode (for you Mac users) so it would not build my project unless I had the proper setting (since its using git):

    Run Script placed after Dependencies (using /bin/ksh as the shell):

    if [ "$(git config --global --get user.email)" != "dhoerl@.com" ]
    then
        exit 1
    fi
    

    EDIT: added tests for new files existence and copying old files to /tmp to address comment by @naomik below.

提交回复
热议问题