1

I set up two SSH keys corresponding to two separate GitHub accounts and the ergonomics of my set up aren't quite working for me.

Somewhere (I can't remember where), I have it set up such that if I'm in the dev folder, it commits with my zackshapiro account and if I'm in my other-dev folder, it commits with my alt_account.

Here's my ~.ssh/config:

Host zackshapiro
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes

Host alt_account
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

Host *
    AddKeysToAgent yes
    UseKeychain yes

And my .zshrc:

alias ssh-personal="ssh-add -D; ssh-add -K ~/.ssh/id_rsa"
alias ssh-alt="ssh-add -D; ssh-add -K ~/.ssh/id_ed25519"

What's become annoying though are problems with git clone, and git push primarily, where I get errors such as these:

When I git push, I'll get

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

And I have to do git push git@github.com:{account}/{project} to get the code to push up.

Similarly with git clone, I can't just do git clone {and paste the link directly from GH}.

I have to do git clone git@github.com:/{account}/{project}

I'd really like to fix the ergonomics of this so I don't have to search my history, change the text of a previous push or clone and can generally move faster.

Any help would be greatly appreciated!

Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151

1 Answers1

0
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

   git push --set-upstream origin main

That "ergonomic" was fixed with Git 2.37 (Q2 2022), which allows you to forget about --track or --set-upstream-to with:

git config --global push.autoSetupRemote true

A git push would automatically link the current local and remote branch.

If you can upgrade your Git to 2.37 or the (current) latest 2.38.1, said push would be easier.


Somewhere (I can't remember where), I have it set up such that if I'm in the dev folder, it commits with my zackshapiro account and if I'm in my other-dev folder, it commits with my alt_account.

This is usually done with git config includeIf directives (Git 2.13, Q2 2017).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250