Git use Multiple Accounts on one computer

Git How to Use Multiple Accounts on Windows or Ubuntu

  • Generating SSH Keys for users

    • Generate a New SSH key

        ssh-keygen -t rsa -b 4096 -C https://www.EasiestSoft.com
      
    • Add SSH key to GitHub

        sudo apt install xclip
        xclip -sele clip ~/.ssh/id_rsa.pub
      

      Now you have the key copied, it's time to add it into GitHub

  • Edit ~/.ssh/config to add multiple host

    EasiestSoft@linux:~$ vi ~/.ssh/config
    Host github-EasiestSoft
        HostName github.com
        User git
        IdentityFile /path/to/github-EasiestSoft.id_rsa
        IdentitiesOnly yes
    
    Host github-dcba
        HostName github.com
        User git
        IdentityFile /path/to/github-dcba.id_rsa
        IdentitiesOnly yes
    
  • Setting up Git on local computer

    cd SSH-Server-to-Server
    git init
    git config user.name EasiestSoft
    git config user.email EasiestSoft@users.noreply.github.com
    git remote add origin github-EasiestSoft:/EasiestSoft/SSH-Server-to-Server.git
    git pull origin master
    
    cd another-repo
    git config user.name dcba
    git config user.email dcba@users.noreply.github.com)
    git remote add origin github-dcba:/EasiestSoft/another-repo.git
    git pull origin master
    

Be careful! in order to protect your privacy, do not use your real Email address for git Email setting

Git command line tips and tricks

  • Push all to GitHub

    git add -A
    git commit -m "first commit"
    git push origin master
    
  • Git stop tracking files

    git update-index --assume-unchanged [path]
  • Git add un-tracked files
    git update-index -h
    git update-index --no-assume-unchanged [path]
  • Undoing a git push
    git push -f origin last_known_good_commit:branch_name
  • Nuke last commit and never see it again
    git reset --hard HEAD~1

©2012-2019 EasiestSoft