{"id":19739013,"url":"https://github.com/fpopic/.gitconfig-setup","last_synced_at":"2025-05-08T23:42:23.543Z","repository":{"id":41482543,"uuid":"509824692","full_name":"fpopic/.gitconfig-setup","owner":"fpopic","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-30T06:18:22.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-12T01:15:52.191Z","etag":null,"topics":["git","gitconfig","github","gitlab","gpg","pbcopy","ssh"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fpopic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-02T17:50:48.000Z","updated_at":"2024-09-03T08:09:58.000Z","dependencies_parsed_at":"2023-01-30T16:40:50.037Z","dependency_job_id":null,"html_url":"https://github.com/fpopic/.gitconfig-setup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpopic%2F.gitconfig-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpopic%2F.gitconfig-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpopic%2F.gitconfig-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fpopic%2F.gitconfig-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fpopic","download_url":"https://codeload.github.com/fpopic/.gitconfig-setup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233400350,"owners_count":18670677,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","gitconfig","github","gitlab","gpg","pbcopy","ssh"],"created_at":"2024-11-12T01:15:57.559Z","updated_at":"2025-01-10T19:40:42.140Z","avatar_url":"https://github.com/fpopic.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# .gitconfig-setup\n\nHow to prepare your git environment to work:\n- with different auth `ssh` and signing `gpg` keys\n- with different git hosts (e.g. GitHub, GitLab) and organization (private account, company account) \n- with automatic key selection based on the folder path and ssh host\n\nSteps:\n1. Generate new [SSH private key(s)](https://docs.gitlab.com/ee/user/ssh.html#generate-an-ssh-key-pair)\n    - Generating a private key with a **passphrase** is a requirement on Mac :warning:\n      ```shell\n      $ ssh-keygen -t ED25519 -C \"your@github.email\" -f ~/.ssh/id_org1_github\n      $ pbcopy ~/.ssh/id_org1_github.pub\n      $ open https://github.com/settings/keys\n  \n      $ ssh-keygen -t ED25519 -C \"your@gitlab.email\" -f ~/.ssh/id_org3_gitlab\n      $ pbcopy ~/.ssh/id_org3_gitlab.pub\n      $ open https://gitlab.com/-/profile/keys\n      ```\n    - [Make keys \"persistent\"](https://unix.stackexchange.com/a/560404/171941) automatically loaded after Mac reboot\n    - Update `~/.ssh/config` file:\n      ```config\n      Host *\n          UseKeychain yes\n          AddKeysToAgent yes\n          IgnoreUnknown UseKeychain\n      \n      Host org1-github\n          user = git\n          HostName = github.com\n          identityfile = ~/.ssh/id_org1_github\n          identitiesonly yes           \n\n      Host org3-gitlab\n          HostName = gitlab.com\n          user = git\n          identityfile = ~/.ssh/id_org3_gitlab\n          identitiesonly yes\n      ```\n    - For GitHub make sure you authorized your ssh key with [your organization via SSO](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-an-ssh-key-for-use-with-saml-single-sign-on)\n\n1. Generate new [GPG signing key(s)](https://docs.gitlab.com/ee/user/project/repository/gpg_signed_commits/)\n    - Execute\n      ```shell\n      $ gpg --gen-key\n      ```\n    - Note your GPG key ID, It begins after the `/` character in the `sec` paragraph after executing:\n      ```shell\n      $ gpg --list-secret-keys --keyid-format LONG first.last@organisation1.com\n      sec   rsa3072/\u003cGPG KEY ID IS HERE\u003e 2022-03-03 [SC]\n            5A233D97F169400541080D50D58FC20EB4027CXX\n      uid                 [ultimate] first last \u003cfirst.last@organisation1.com\u003e\n      ssb   rsa3072/560358F2315DB6XX 2022-03-03 [E]\n      ```\n\n1. Set up `~/.gitconfig` so that it automatically picks up your git config based on the folder prefix\n  - We suggest to follow folder paths for all git repositories\n    ```shell\n    ~/Projects\n    ├── github\n    │   ├── my-organisation1\n    │   │   ├── repo-1\n    │   │   └── ...\n    │   └── my-organisation2\n    │       ├── repo-2\n    │       └── ...\n    ├── gitlab\n    │   └── my-organisation3\n    │       ├── repo-3\n    │       └── ...\n    ├── bitbucket\n    │   └── my-organisation4\n    │       ├── repo-4\n    │       └── ...\n    ...\n    ```\n  - `~/.gitconfig` \n    ```ini\n    [commit]\n    gpgsign = true\n\n    [includeIf \"gitdir:~/Projects/github/my-organisation1/\"]\n    path = ~/.gitconfig-github-my-organisation1\n\n    [includeIf \"gitdir:~/Projects/gitlab/my-organisation3/\"]\n    path = ~/.gitconfig-gitlab-my-organisation3\n    ```\n\n  - `~/.gitconfig-github-my-organisation1`\n    ```ini\n    [user]\n    email = first.last@organisation1.com\n    name = your-github-username\n    signingkey = your GPG key ID\n\n    [url \"ssh://git@org1-github/umg/\"]\n    insteadOf = git@github.com:org1/\n    ```\n\n  - `~/.gitconfig-gitlab-my-organisation3`\n    ```ini\n    [user]\n    email = first.last@organisation3.com\n    name = your-gitlab-username\n    signingkey = your GPG key ID\n\n    [url \"ssh://git@org3-gitlab/umg/\"]\n    insteadOf = git@gitlab.com:org3/\n    ```\n\n4. Make sure everything works by cloning some repositories using git ssh protocol\n\n## Troubleshooting\n\n1. Read git config variables from respective paths\n    ```shell\n    $ cd ~/Projects/github/my-organisation1/repo-1 on main\n    $ git config --show-origin --get user.name\n    \n    file:~/.gitconfig-github-my-organisation1 your-github-username\n    ```\n    \n    ```shell\n    $ cd ~/Projects/gitlab/my-organisation3/repo-3 on main\n    $ git config --show-origin --get user.name\n\n    file:~/.gitconfig-gitlab-my-organisation3 your-gitlab-username\n    ```\n    \n1. If you get the error: `gpg failed to sign the data` try running `$ export GPG_TTY=$(tty)` before committing and add it to your `~/.zshrc` config if it helped\n    ```shell\n    $ echo 'export GPG_TTY=$(tty)' \u003e\u003e ~/.zshrc\n    $ source ~/.zshrc\n    ```\n\n1. Check ssh auth log what is happening under the hood\n    ```shell\n    $ ssh -Tv git@github.com\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffpopic%2F.gitconfig-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffpopic%2F.gitconfig-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffpopic%2F.gitconfig-setup/lists"}