

Assuming your github username for your new account is someuser. Now, to configure your repo to "talk" to github using the correct identity/credentials, we have add a remote. $ git config user.email make your first commit $ echo "hello world" > readmeĬheck the commit to see your new identity was used using git log $ git log -pretty="%H %an "į397a7cfbf55d44ffdf87aa24974f0a5001e1921 Mister Manager Īlright, time to push to github! Since github doesn't know about our new repo yet, first go to /new and create your new repo – name it somerepo Now configure this repo to use your identity $ git config user.name "Mister Manager" You can follow along with me if you'd like $ cd ~ Let's assume you've already done a little work locally and you're now ready to push to github. This situation applies to users that are create new content using their secondary github account. Well because you can't have a chicken without and egg, we'll look at publishing a new repo on your secondary account. That correctly connects git to the corresponding IdentityFile and properly authenticates you with github That bolded portion must match the Host name we setup in your ~/.ssh/config file. Let's say /someorg/somerepo already exists and you were added to it – cloning is as easy as $ git clone -otheruser:someorg/somerepo.git

This situation might apply to you if you have a new github account for your workplace and you were added to a company project. So how does this come together to work with git and github? Well because you can't have a chicken without and egg, we'll look at cloning an existing repo.
GIT BASH WINDOWS CLIENT HOW TO
Now your new user identity is all setup – below we'll show you how to use it. Ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDBVvWNQ2nO5. You can get the public key contents using: copy/paste it to github $ cat ~/.ssh/github-otheruser.pub Head over to /settings/keys to add your new public key
GIT BASH WINDOWS CLIENT UPDATE
If you don't want to favour one account over another, I'll show you how to update existing repos on your system to use an updated ssh configuration. For that reason, the "default" Host is setup to use your mainuser key. Presumably, you'll have some existing repos associated with your primary github identity. Open that with your favourite editor, and add the following contents Host We'll create it with the proper owner-read/write-only permissions $ (umask 077 touch ~/.ssh/config) Next, we need to setup a ~/.ssh/config file that will define our key configurations. Now, when we look at tree ~/.ssh we see $ tree ~/.ssh Next, let's generate a new key pair – here I'll name the new key github-otheruser $ ssh-keygen -t rsa -b 4096 -f ~/.ssh/github-otheruser Right now your tree ~/.ssh looks like this $ tree ~/.sshįirst, name that key pair – adding a descriptive name will help you remember which key is used for which user/remote # change to your ~/.ssh directory To manage a git repo under a separate github/bitbucket/whatever account, you simply need to generate a new SSH key.īut before we can start pushing/pulling repos with your second identity, we gotta get you into shape – Let's assume your system is setup with a typical id_rsa and id_rsa.pub key pair. Some of you may require different emails to be used for different repositories, from git 2.13 you can set the email on a directory basis by editing the global config file found at: ~/.gitconfig using conditionals like so: Īnd then your work-specific config ~/work/.gitconfig would look like this: Įmail = you for informing me of this in the comments. Setting user name, email and GitHub token – Overriding settings for individual repos IdentityFile ~/.ssh/id_ed25519_doe_companyĪdd your remote: git remote add origin change using: git remote set-url origin if you're working with multiple repositories using different personas, you need to make sure that your individual repositories have the user settings overridden accordingly: id_ed25519_example_company.Ĭopy the SSH public-key to GitHub from ~/.ssh/id_ed25519_doe_company.pub and tell ssh about the key: ssh-add ~/.ssh/id_ed25519_doe_companyĬreate a config file in ~/.ssh with the following contents: Host github-doe-company Generate an SSH-key: ssh-keygen -t ed25519 -C the prompts and decide a name, e.g. This link is easy to follow (Thanks Eric):


All you need to do is configure your SSH setup with multiple SSH keypairs.
