{"id":1043,"date":"2019-09-08T08:21:24","date_gmt":"2019-09-08T08:21:24","guid":{"rendered":"http:\/\/tech.avant.net\/q\/?p=1043"},"modified":"2019-12-06T04:59:04","modified_gmt":"2019-12-06T04:59:04","slug":"multiple-git-remotes","status":"publish","type":"post","link":"https:\/\/tech.avant.net\/q\/multiple-git-remotes\/","title":{"rendered":"multiple git remotes"},"content":{"rendered":"\n<p>I would like to manage a project across multiple remote git repositories, specifically, a public github repository and my own private repositories.<\/p>\n\n\n\n<p>Fortunately, git supports as many remote repositories as you need. When you clone a repository, there will be a default remote called &#8220;origin&#8221;, i.e.,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git clone git@github.com:timwarnock\/dotfiles.git\n...\n$ cd dotfiles\n$ git remote -v\norigin\tgit@github.com:timwarnock\/dotfiles.git (fetch)\norigin\tgit@github.com:timwarnock\/dotfiles.git (push)<\/pre>\n\n\n\n<p>Adding additional remotes is trivial, i.e.,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git remote add bob https:\/\/example.com\/bob\/dotfiles\n$ git remote add ann https:\/\/example.com\/ann\/dotfiles\n$ git remote add pat https:\/\/example.com\/pat\/dotfiles<\/pre>\n\n\n\n<p>Now, when we look at the remotes for our repository we&#8217;ll see the new entries,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git remote -v\norigin\tgit@github.com:timwarnock\/dotfiles.git (fetch)\norigin\tgit@github.com:timwarnock\/dotfiles.git (push)\nbob\thttps:\/\/example.com\/bob\/dotfiles (fetch)\nbob\thttps:\/\/example.com\/bob\/dotfiles (push)\nann\thttps:\/\/example.com\/ann\/dotfiles (fetch)\nann\thttps:\/\/example.com\/ann\/dotfiles (push)\npat\thttps:\/\/example.com\/pat\/dotfiles (fetch)\npat\thttps:\/\/example.com\/pat\/dotfiles (push)<\/pre>\n\n\n\n<p>If we want to pull from Ann&#8217;s repository and merge it into our local master branch,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git pull ann master<\/pre>\n\n\n\n<p>And then if we wanted to push those changes to Bob&#8217;s repository,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git push bob master<\/pre>\n\n\n\n<p>We can also rename and remove remotes, i.e.,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git remote rename bob bobbie\n...\n$ git remote remove bobbie<\/pre>\n\n\n\n<p>In practice, we may not want to be constantly merging everything into a local master, instead, we may want to investigate the code before any merges. This can be done easily. I prefer to use tracked branches, as follows,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git checkout -b bob-master\n$ git remote add bob https:\/\/example.com\/bob\/dotfiles\n$ git fetch bob master\n$ git --set-upstream-to=bob\/master<\/pre>\n\n\n\n<p>We can now inspect the bob-master branch and merge manually as we see fit,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git checkout bob-master\n$ git pull\n...\n$ git checkout master\n$ git diff bob-master\n...<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I would like to manage a project across multiple remote git repositories, specifically, a public github repository and my own private repositories. Fortunately, git supports as many remote repositories as you need. When you clone a repository, there will be a default remote called &#8220;origin&#8221;, i.e., Adding additional remotes is trivial, i.e., Now, when we [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,22],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/1043"}],"collection":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/comments?post=1043"}],"version-history":[{"count":9,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/1043\/revisions"}],"predecessor-version":[{"id":1053,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/1043\/revisions\/1053"}],"wp:attachment":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/media?parent=1043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/categories?post=1043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/tags?post=1043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}