This article was originally published in our UncaughtException blog. Read this article in there by following this link.
Cover photo by Brina Blum ...
For further actions, you may consider blocking this person and/or reporting abuse
Lot of steps to be be able to add a comment! Anyway, if you read this post and git is not using the correct information, maybe that's because you can't explicit set configurations after the
[includeIf]
. You must include a file instead.Only after reading the git-config documentation, and noticing that they talk a lot about a
path
property, I decided to move thesshCommand
to another file. And then it finally worked correctly. What I currently have:Arnelle, thanks for this post. It's way better then using custom hosts!
I don't know why but I can't get it done in my case. After using
ssh -i ~/.ssh/work_key
and thengit clone my_repo_url
, it still shows errors of no permission. I tried addcommand clause
as well but the result is still the same. Have no clues why it couldn't be done. Could you pls help?Hello! Hmm I can think of a few things you can check to troubleshoot this:
work_key
's public key to your GitHub account's SSH Keys?git@...
url (not sure if this makes a difference but worth trying hehe)Please let me know how it goes! :)
I had the same problem as you. I had to restart my Macbook in order for it to work.
This does not work for me and it took me half a day to debug to figure out why. Here's the thing:
Even though you have an
ssh -i
section in the git config, this does not work for pushing to remote repositories. This is because for some reason that git always prefers.ssh/config
and this defaults to my "user" key and not my "work" key. Therefore, pushing to a work-repository, even withssh -i
, it finds the personal user key first and I'll get a persmission denied for "user" error from github.Only setting up different hosts in
.ssh/config
fixed this for me. I know it was your entire point of this post to say, "the nicer way," but maybe you have just forgotten about this config?Or are you using the same SSH key for different accounts? I would not recommend doing that. Anyways, thank you for this article. :)
Hi Arnelle,
Thank's for this tip !
Is it possible to do something like this :
Thank's again !
From documentation I would say, no. ( git-scm.com/docs/git-config#Docume... ).
But I just checked it in WSL and it looks to work.
Correction. Iput:
[includeIf "gitdir:~/work/*/ome"]
[user]
email = "work@email.com"
And it matched
~/work/test
So it seems to match to much.or just ignores everything after a wildcard.
I would suggest using symlinks, but I see that you are using windows.
Thank's man !
@yafkari : it looks like it matches to much. Please read comment above.
Maybe if you are constrained to windows try using WSL and then symlinks there. (but works with Windows 10 only :( ).
I believe Afri is correct about pushing changes to a remote using the
~/.ssh/config
. I was able to workaround the issue by telling ssh to ignore the config files using the-F
option.Specifying the value
none
tells ssh to ignore all configuration files. (ssh doc)Thanks, this works really nicely on windows as of 09/2021. I only found your method because it turns out that my ISP's DNS servers block SSH connections to GitHub and I was trying every method. Yours is the best by the way.
This is exactly what I needed. Bless you.
I use
ssh-add
and it might cause some issues. Make sure the keys are added in the order ofcondition includes
thanks for sharing this with us 🎉
Thanks bai arnelle
You're welcome! 🎉