Files
fundor333.com/data/webmentions/71c47bb8a913deaae9992bd7f6de515b.json
fundor333 7437fda25f 👾Fetch webmentions
skip-checks: true
2025-04-15 18:06:26 +00:00

1 line
14 KiB
JSON

{"source": [{"type": "entry", "author": {"type": "card", "name": "Jamie Tanna", "photo": "https://avatars.webmention.io/www.jvt.me/f0f487b73880b54411ec067322d1d32edcb4b125853353123e076183d1131acf.png", "url": "https://www.jvt.me"}, "url": "https://www.jvt.me/mf2/2021/12/yupzj/", "published": "2021-12-23T17:02:50", "wm-received": "2021-12-23T17:14:27Z", "wm-id": 1321673, "wm-source": "https://www.jvt.me/mf2/2021/12/yupzj/", "wm-target": "https://fundor333.com/post/2021/advance-git-config-and-ssh-config/", "wm-protocol": "webmention", "like-of": "https://fundor333.com/post/2021/advance-git-config-and-ssh-config/", "wm-property": "like-of", "wm-private": false, "rels": {"canonical": "https://www.jvt.me/mf2/2021/12/yupzj/"}}, {"type": "entry", "author": {"type": "card", "name": "benji", "photo": "https://avatars.webmention.io/benji.dog/98f50ccee2f72b224906440e0a78cc1fa5ea016ae65e5fa0d42ff5000ad29d24.jpg", "url": "https://benji.dog"}, "url": "https://www.benji.dog/articles/git-config/", "published": "2024-11-22T00:00:00", "wm-received": "2024-11-23T05:32:56Z", "wm-id": 1861724, "wm-source": "https://www.benji.dog/articles/git-config/", "wm-target": "https://fundor333.com/post/2021/advance-git-config-and-ssh-config/", "wm-protocol": "webmention", "summary": {"content-type": "text/plain", "value": "This may be overkill, but it works on my machine"}, "content": {"html": "<blockquote>\n<p><strong>Note</strong>: I've had this post drafted for 3 YEARS!!! It's finally time to publish it.</p>\n</blockquote>\n<p>I like to mess with my <a href=\"https://github.com/benjifs/dotfiles\">dotfiles</a> and every so often, I find out about a new way to do things and I spend more time than I should learning how to use it.</p>\n<p>A few years ago I learned about <a href=\"https://git-scm.com/docs/git-config#_includes\">includeIf</a> for including specific files if some condition was met for <code>git</code>. The example that I first saw was doing:</p>\n<pre><code>[includeIf \"gitdir:~/code/**\"]\n path = ~/.config/git/personal\n[includeIf \"gitdir:~/work/**\"]\n path = ~/.config/git/work\n</code></pre>\n<p>So that <code>~/.config/git/personal</code> is only included for <code>git</code> directories under <code>~/code</code> and <code>~/.config/git/work</code> is only included for directories under <code>~/work</code>. The contents of those included files varies but usually it contains your git identity, signing keys, etc. Here's an example of what that could look like:</p>\n<pre><code>[user]\n name = benji\n email = benji@work.com\n signingkey = ~/.ssh/work.id_ed25519.pub\n</code></pre>\n<p>That works pretty well but I usually organize all my code in <code>~/workspace</code> regardless of whether its personal, <strong>work-1</strong>, <strong>work-2</strong>, etc. I wanted to be able to configure git depending on where that repo actually lives instead of where the directory is in my machine. Then I found out about <a href=\"https://git-scm.com/docs/git-config#Documentation/git-config.txt-codehasconfigremoteurlcode\">hasconfig:remote.*.url:</a>!</p>\n<p>This makes it so that I can configure git conditionally if the given remote URL exists for that directory I'm currently working in.</p>\n<p>A few examples of what I do is:</p>\n<pre><code>[includeIf \"hasconfig:remote.*.url:git@github.com:orgname/**\"]\n path = ~/.config/git/config-gh-org\n\n[includeIf \"hasconfig:remote.*.url:git@github.com:*/**\"]\n path = ~/.config/git/config-gh\n\n[includeIf \"hasconfig:remote.*.url:git@gitlab.com:*/**\"]\n path = ~/.config/git/config-gl\n\n[includeIf \"hasconfig:remote.*.url:git@git.sr.ht:*/**\"]\n path = ~/.config/git/config-srht\n</code></pre>\n<p>Now if I'm in a directory where the remote matches <code>github.com:orgname/**</code> it would use <code>~/.config/git/config-gh-org</code>, otherwise it uses the general config file for any other GitHub repo.</p>\n<p>While that handles git identities, I still need to configure SSH keys separately to be able to <code>pull</code> and <code>push</code> to remotes. The simple version of my <code>~/.ssh/config</code> looks like this:</p>\n<pre><code>Host gitlab.com\nHostname gitlab.com\nUser git\nIdentityFile ~/.ssh/gitlab.id_ed25519\n\nHost github.com\nHostname github.com\nUser git\nIdentityFile ~/.ssh/github.id_ed25519\n</code></pre>\n<p>The only problem with this is that in order to use a different <code>IdentityFile</code> for the same <code>Hostname</code> so that I could use a different key for repos under <code>github.com/orgname</code>, I'd have to use a different value for <code>Host</code>. So in my case I would add the following to my <code>~/.ssh/config</code>:</p>\n<pre><code>Host gh-work\nHostname github.com\nUser git\nIdentityFile ~/.ssh/work.id_ed25519\n</code></pre>\n<p>Finally, to use that <code>Host</code> when I'm looking for a repo in <code>github.com/orgname</code>, I would add the following to my git config:</p>\n<pre><code>[url \"gh-work:orgname\"]\n insteadOf = git@github.com:orgname\n</code></pre>\n<p>So when I <code>clone</code>, <code>pull</code>, or <code>push</code> a repo that's under my work's org account I can do:</p>\n<pre><code>git clone git@github.com:orgname/project\n</code></pre>\n<p>and <code>insteadOf</code> would replace <code>github.com:orgname</code> with <code>gh-work:orgname</code> so that it uses the right info from my SSH config. It's a neat trick which I saw referenced in this <a href=\"https://www.kenmuse.com/blog/ssh-and-multiple-git-credentials/#git\">article</a>.</p>\n<p>Are there any issues with this approach? Is there a better way to do this? I'm not sure so please let me know as I'd love to learn and I'll update this post accordingly.</p>\n<h2>References</h2>\n<ul><li><a href=\"https://fundor333.com/post/2021/advance-git-config-and-ssh-config/\">https://fundor333.com/post/2021/advance-git-config-and-ssh-config/</a></li>\n<li><a href=\"https://www.kenmuse.com/blog/ssh-and-multiple-git-credentials/#git\">https://www.kenmuse.com/blog/ssh-and-multiple-git-credentials/#git</a></li>\n<li><a href=\"https://garrit.xyz/posts/2023-10-13-organizing-multiple-git-identities\">https://garrit.xyz/posts/2023-10-13-organizing-multiple-git-identities</a></li>\n<li><a href=\"https://stevenharman.net/configure-ssh-keys-for-multiple-github-accounts\">https://stevenharman.net/configure-ssh-keys-for-multiple-github-accounts</a></li>\n</ul>", "text": "Note: I've had this post drafted for 3 YEARS!!! It's finally time to publish it.\n\nI like to mess with my dotfiles and every so often, I find out about a new way to do things and I spend more time than I should learning how to use it.\nA few years ago I learned about includeIf for including specific files if some condition was met for git. The example that I first saw was doing:\n[includeIf \"gitdir:~/code/**\"]\n path = ~/.config/git/personal\n[includeIf \"gitdir:~/work/**\"]\n path = ~/.config/git/work\n\nSo that ~/.config/git/personal is only included for git directories under ~/code and ~/.config/git/work is only included for directories under ~/work. The contents of those included files varies but usually it contains your git identity, signing keys, etc. Here's an example of what that could look like:\n[user]\n name = benji\n email = benji@work.com\n signingkey = ~/.ssh/work.id_ed25519.pub\n\nThat works pretty well but I usually organize all my code in ~/workspace regardless of whether its personal, work-1, work-2, etc. I wanted to be able to configure git depending on where that repo actually lives instead of where the directory is in my machine. Then I found out about hasconfig:remote.*.url:!\nThis makes it so that I can configure git conditionally if the given remote URL exists for that directory I'm currently working in.\nA few examples of what I do is:\n[includeIf \"hasconfig:remote.*.url:git@github.com:orgname/**\"]\n path = ~/.config/git/config-gh-org\n\n[includeIf \"hasconfig:remote.*.url:git@github.com:*/**\"]\n path = ~/.config/git/config-gh\n\n[includeIf \"hasconfig:remote.*.url:git@gitlab.com:*/**\"]\n path = ~/.config/git/config-gl\n\n[includeIf \"hasconfig:remote.*.url:git@git.sr.ht:*/**\"]\n path = ~/.config/git/config-srht\n\nNow if I'm in a directory where the remote matches github.com:orgname/** it would use ~/.config/git/config-gh-org, otherwise it uses the general config file for any other GitHub repo.\nWhile that handles git identities, I still need to configure SSH keys separately to be able to pull and push to remotes. The simple version of my ~/.ssh/config looks like this:\nHost gitlab.com\nHostname gitlab.com\nUser git\nIdentityFile ~/.ssh/gitlab.id_ed25519\n\nHost github.com\nHostname github.com\nUser git\nIdentityFile ~/.ssh/github.id_ed25519\n\nThe only problem with this is that in order to use a different IdentityFile for the same Hostname so that I could use a different key for repos under github.com/orgname, I'd have to use a different value for Host. So in my case I would add the following to my ~/.ssh/config:\nHost gh-work\nHostname github.com\nUser git\nIdentityFile ~/.ssh/work.id_ed25519\n\nFinally, to use that Host when I'm looking for a repo in github.com/orgname, I would add the following to my git config:\n[url \"gh-work:orgname\"]\n insteadOf = git@github.com:orgname\n\nSo when I clone, pull, or push a repo that's under my work's org account I can do:\ngit clone git@github.com:orgname/project\n\nand insteadOf would replace github.com:orgname with gh-work:orgname so that it uses the right info from my SSH config. It's a neat trick which I saw referenced in this article.\nAre there any issues with this approach? Is there a better way to do this? I'm not sure so please let me know as I'd love to learn and I'll update this post accordingly.\nReferences\nhttps://fundor333.com/post/2021/advance-git-config-and-ssh-config/\nhttps://www.kenmuse.com/blog/ssh-and-multiple-git-credentials/#git\nhttps://garrit.xyz/posts/2023-10-13-organizing-multiple-git-identities\nhttps://stevenharman.net/configure-ssh-keys-for-multiple-github-accounts"}, "mention-of": "https://fundor333.com/post/2021/advance-git-config-and-ssh-config/", "wm-property": "mention-of", "wm-private": false, "rels": {"canonical": "https://benji.dog/articles/git-config/"}}], "stats": {"like-of": 1, "bookmark-of": 0, "mention-of": 1, "repost-of": 0, "in-reply-to": 0, "comments": [{"content": "Note: I've had this post drafted for 3 YEARS!!! It's finally time to publish it.\n\nI like to mess with my dotfiles and every so often, I find out about a new way to do things and I spend more time than I should learning how to use it.\nA few years ago I learned about includeIf for including specific files if some condition was met for git. The example that I first saw was doing:\n[includeIf \"gitdir:~/code/**\"]\n path = ~/.config/git/personal\n[includeIf \"gitdir:~/work/**\"]\n path = ~/.config/git/work\n\nSo that ~/.config/git/personal is only included for git directories under ~/code and ~/.config/git/work is only included for directories under ~/work. The contents of those included files varies but usually it contains your git identity, signing keys, etc. Here's an example of what that could look like:\n[user]\n name = benji\n email = benji@work.com\n signingkey = ~/.ssh/work.id_ed25519.pub\n\nThat works pretty well but I usually organize all my code in ~/workspace regardless of whether its personal, work-1, work-2, etc. I wanted to be able to configure git depending on where that repo actually lives instead of where the directory is in my machine. Then I found out about hasconfig:remote.*.url:!\nThis makes it so that I can configure git conditionally if the given remote URL exists for that directory I'm currently working in.\nA few examples of what I do is:\n[includeIf \"hasconfig:remote.*.url:git@github.com:orgname/**\"]\n path = ~/.config/git/config-gh-org\n\n[includeIf \"hasconfig:remote.*.url:git@github.com:*/**\"]\n path = ~/.config/git/config-gh\n\n[includeIf \"hasconfig:remote.*.url:git@gitlab.com:*/**\"]\n path = ~/.config/git/config-gl\n\n[includeIf \"hasconfig:remote.*.url:git@git.sr.ht:*/**\"]\n path = ~/.config/git/config-srht\n\nNow if I'm in a directory where the remote matches github.com:orgname/** it would use ~/.config/git/config-gh-org, otherwise it uses the general config file for any other GitHub repo.\nWhile that handles git identities, I still need to configure SSH keys separately to be able to pull and push to remotes. The simple version of my ~/.ssh/config looks like this:\nHost gitlab.com\nHostname gitlab.com\nUser git\nIdentityFile ~/.ssh/gitlab.id_ed25519\n\nHost github.com\nHostname github.com\nUser git\nIdentityFile ~/.ssh/github.id_ed25519\n\nThe only problem with this is that in order to use a different IdentityFile for the same Hostname so that I could use a different key for repos under github.com/orgname, I'd have to use a different value for Host. So in my case I would add the following to my ~/.ssh/config:\nHost gh-work\nHostname github.com\nUser git\nIdentityFile ~/.ssh/work.id_ed25519\n\nFinally, to use that Host when I'm looking for a repo in github.com/orgname, I would add the following to my git config:\n[url \"gh-work:orgname\"]\n insteadOf = git@github.com:orgname\n\nSo when I clone, pull, or push a repo that's under my work's org account I can do:\ngit clone git@github.com:orgname/project\n\nand insteadOf would replace github.com:orgname with gh-work:orgname so that it uses the right info from my SSH config. It's a neat trick which I saw referenced in this article.\nAre there any issues with this approach? Is there a better way to do this? I'm not sure so please let me know as I'd love to learn and I'll update this post accordingly.\nReferences\nhttps://fundor333.com/post/2021/advance-git-config-and-ssh-config/\nhttps://www.kenmuse.com/blog/ssh-and-multiple-git-credentials/#git\nhttps://garrit.xyz/posts/2023-10-13-organizing-multiple-git-identities\nhttps://stevenharman.net/configure-ssh-keys-for-multiple-github-accounts", "link": "https://www.benji.dog/articles/git-config/", "author_name": "benji", "author_photo": "https://avatars.webmention.io/benji.dog/98f50ccee2f72b224906440e0a78cc1fa5ea016ae65e5fa0d42ff5000ad29d24.jpg", "author_url": "https://benji.dog"}]}}