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
    • Add SSH key to GitHub

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

      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
        User git
        IdentityFile /path/to/github-EasiestSoft.id_rsa
        IdentitiesOnly yes
    Host github-dcba
        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 EasiestSoft
    git config
    git remote add origin github-EasiestSoft:/EasiestSoft/SSH-Server-to-Server.git
    git pull origin master
    cd another-repo
    git config dcba
    git config
    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