{"componentChunkName":"component---src-templates-blog-post-template-js","path":"/2019/01/27/multiple-git-profiles/","result":{"data":{"mdx":{"id":"048815a1-2f7e-5453-a114-1910b6d94baf","frontmatter":{"title":"Setting up multiple Git providers","date":"2019 January 27th","cover":{"id":"3f6b597a-9a16-5e58-937e-c77d1176d2c6","publicURL":"/static/cover-9aa19f85f98ab76e5655c65c2fa7b2be.jpg"}},"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"date\": \"2019-01-27T00:00:00.000Z\",\n  \"title\": \"Setting up multiple Git providers\",\n  \"tags\": [\"information\", \"learning\", \"guide\", \"wsl\", \"bash on windows\", \"git\"],\n  \"published\": true,\n  \"cover\": \"./cover.jpg\",\n  \"coverCredit\": \"Photo by Evelyn on Unsplash\"\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"Over the past couple of weeks now I have set up several development\\nmachines at work and have had to also use two git accounts, GitHib and\\nBitbucket.\"), mdx(\"p\", null, \"To connect to both I use SSH as a preference, I have been using SSH in\\nplace of HTTPS for quite some time now, if you want to connect\\nrepeatedly without having to provide user name and password details\\nthen SSH is a good option.\"), mdx(\"p\", null, \"If you are unfamiliar with using SSH to authenticate with git then\\ntake a look at my cheat sheets repository (\", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"https://github.com/spences10/cheat-sheets\",\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }), \"ss10.me/cheat-sheets\"), \")\\nthere are several sections covering SSH, notably:\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"a\", _extends({\n    parentName: \"li\"\n  }, {\n    \"href\": \"https://github.com/spences10/cheat-sheets/blob/master/git.md#how-to-authenticate-with-github-using-ssh\",\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }), \"How to Authenticate with GitHub Using SSH\")), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"a\", _extends({\n    parentName: \"li\"\n  }, {\n    \"href\": \"https://github.com/spences10/cheat-sheets/blob/master/git.md#use-multiple-ssh-keys\",\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }), \"Use multiple SSH Keys\"), \" (what this post is covering)\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"a\", _extends({\n    parentName: \"li\"\n  }, {\n    \"href\": \"https://github.com/spences10/cheat-sheets/blob/master/git.md#re-use-ssh-keys-from-one-machine-to-another\",\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }), \"Re Use SSH Keys from one Machine to Another\"))), mdx(\"p\", null, \"I have come across this set-up a few times now and implemented it for\\nmyself.\"), mdx(\"p\", null, \"You\\u2019ll need to create a \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"config\"), \" file in the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \".ssh\"), \" folder in your\\nhome directory (Windows, Ubuntu or both if you use a \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"https://thelocalhost.blog/wsl-bootstrap-2019\",\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }), \"WSL set-up\"), \")\\ncheck with:\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"ll ~/.ssh/\\n\")), mdx(\"p\", null, \"This will list out the contents of the folder, if you get\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"No such file or directory\"), \" then you don\\u2019t have SSH configured.\"), mdx(\"p\", null, \"Take a look at the \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"https://github.com/spences10/cheat-sheets/blob/master/git.md#how-to-authenticate-with-github-using-ssh\",\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }), \"How to Authenticate with GitHub Using SSH\"), \" section\\non the cheat-sheets repo for details on that.\"), mdx(\"p\", null, \"For this example let\\u2019s presume that we have already created our SSH\\nkeys for Bitbucket and GitHub and authenticated with both Bitbucket\\nand GitHub.\"), mdx(\"p\", null, \"Next create a \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"config\"), \" file:\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"nano ~/.ssh/config\\n\")), mdx(\"p\", null, \"This will open a new file with nano that we can add the following to:\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"# Bitbucket (default)\\n  Host bb\\n  HostName bitbucket.org\\n  User git\\n  IdentityFile ~/.ssh/id_default\\n\\n# Github (secondary)\\n  Host gh\\n  HostName github.com\\n  User git\\n  IdentityFile ~/.ssh/id_secondary\\n\")), mdx(\"p\", null, \"Just remember that the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"IdentityFile\"), \" needs to match what you have\\ncalled your SSH keys.\"), mdx(\"p\", null, \"Check current permissions with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"stat\"), \":\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"# stat -c \\\"%a %n\\\" ~/.ssh/*\\n644 /home/scott/.ssh/config\\n700 /home/scott/.ssh/id_default\\n700 /home/scott/.ssh/id_default.pub\\n700 /home/scott/.ssh/id_secondary\\n700 /home/scott/.ssh/id_secondary.pub\\n\")), mdx(\"p\", null, \"Change the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"config\"), \" file permissions as needed:\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"chmod 644 ~/.ssh/config\\n\")), mdx(\"h2\", {\n    \"id\": \"multiple-users\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", _extends({\n    parentName: \"h2\"\n  }, {\n    \"href\": \"#multiple-users\",\n    \"aria-label\": \"multiple users permalink\",\n    \"className\": \"anchor-toc before\"\n  }), mdx(\"svg\", _extends({\n    parentName: \"a\"\n  }, {\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }), mdx(\"path\", _extends({\n    parentName: \"svg\"\n  }, {\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  })))), \"Multiple users\"), mdx(\"p\", null, \"Ok now we should be able to push and pull to the respective GitHub and\\nBitbucket repositories, \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"but\"), \" unless you have the same username and\\nemail address for GitHub and Bitbucket then we\\u2019re also going to need\\nto specify specific user details for the repositories we\\u2019re accessing,\\notherwise the details specified in the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"~/.gitconfig\"), \" are what will be\\nused with commits.\"), mdx(\"p\", null, \"In my case for work my default user account is Bitbucket so that is\\nwhat I have specified in the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"~/.gitconfig\"), \", however for the GitHub\\nrepos I work on I\\u2019ll need to specify my GitHub credentials on a repo\\nby repo basis.\"), mdx(\"p\", null, \"Historically I have gone into the individual repo and manually set the\\nconfig details.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"# from the root of the repo you want to specify the credentials\\ngit config user.name 'Your Name'\\ngit config user.email 'your@email.com'\\n\")), mdx(\"p\", null, \"I have since found an ok solution here:\\n\", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"https://stackoverflow.com/a/43654115/1138354\",\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }), \"https://stackoverflow.com/a/43654115/1138354\")), mdx(\"p\", null, \"Example:\"), mdx(\"p\", null, \"Global config \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"~/.gitconfig\")), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"\\n[user]\\n  name = play.user\\n  email = play.user@gmail.com\\n\\n[includeIf \\\"gitdir:~/work/\\\"]\\n  path = ~/work/.gitconfig\\n\")), mdx(\"p\", null, \"Work specific config \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"~/work/.gitconfig\")), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-bash\"\n  }), \"[user]\\n  name = work.user\\n  email = work.user@megacorp.ltd\\n\")));\n}\n;\nMDXContent.isMDXComponent = true;","excerpt":"Over the past couple of weeks now I have set up several development\nmachines at work and have had to also use two git accounts, GitHib and…","tableOfContents":{"items":[{"url":"#multiple-users","title":"Multiple users"}]},"timeToRead":2,"fields":{"slug":"/2019/01/27/multiple-git-profiles/","editLink":"https://github.com/spences10/thelocalhost.blog/edit/authoring/posts/2019/01/27/multiple-git-profiles/index.md"}}},"pageContext":{"slug":"/2019/01/27/multiple-git-profiles/","previous":{"id":"82832ebd-cf53-5cc8-a3d7-725de1ad3d0a","excerpt":"From scratch to Create React App on Windows An opinionated guide on setting up a web development environment on\nWindows 10 I have been a professional web developer for 10 months now and used\nboth MacOs and Windows in that time. My preferred OS to use…","frontmatter":{"title":"Windows Web-dev bootstrap","date":"2018-12-24T00:00:00.000Z"},"fields":{"slug":"/2018/12/24/wsl-bootstrap-2019/"}},"next":{"id":"ab675f5d-9bed-5185-951c-afd9bcc3a740","excerpt":"Moving to the new hotness!! I've now moved this blog over to Gatsby MDX. You can see all the\nchanges\n on my repo here . From the pull I'm hoping you can glean that the majority of the work\nis in replacing  gatsby-transformer-remark  with  gatsby-mdx…","frontmatter":{"title":"Testing MDX","date":"2019-03-09T00:00:00.000Z"},"fields":{"slug":"/2019/03/09/testing-mdx/"}}}}}