{"id":14,"date":"2011-06-23T21:48:33","date_gmt":"2011-06-23T21:48:33","guid":{"rendered":"http:\/\/imperfectcode.com\/?p=14"},"modified":"2011-06-23T21:48:33","modified_gmt":"2011-06-23T21:48:33","slug":"using-git-to-collaborate-on-a-paper","status":"publish","type":"post","link":"https:\/\/imperfectcode.com\/?p=14","title":{"rendered":"Using git to collaborate on a paper"},"content":{"rendered":"<p>I&#8217;m working with others on a paper written in LaTeX.\u00a0 It&#8217;s stored in a git repository.\u00a0 I figured it would be easy for all of us to track and merge each other&#8217;s changes this way.\u00a0 So my friend clones the repo, commits a change, and sends me an email to let me know.\u00a0 At this point, I thought, great, let&#8217;s grab his changes, review and merge them.<\/p>\n<p>I&#8217;m sure this is obvious and is documented elsewhere, but it wasn&#8217;t to me. It&#8217;s not conceptually different than two programmers sharing code, which I&#8217;m sure is one of the common usages of git.<\/p>\n<p>So I thought, well, I can just track his &#8216;master&#8217; branch in my repo and merge the changes.<\/p>\n<pre># this doesn't work\r\ngit branch --track friend-master\/path\/to\/other\/repo master\r\n<\/pre>\n<p>No, this doesn&#8217;t work.\u00a0 I have to add my friend&#8217;s repo as a remote in my local repo first.<\/p>\n<pre>#this works\r\ngit remote add friend \/path\/to\/other\/repo<\/pre>\n<p>This says &#8220;Hey, I&#8217;m interested in the repo at \/path\/to\/other\/repo , and from now on I&#8217;m calling it &#8220;friend.&#8221; Does this mean I can track the branch now?<\/p>\n<pre>#not yet\r\ngit branch --track friend-master friend\/master<\/pre>\n<p>No, first I have to fetch the remote so that my local repo is aware of what branches exist there.<\/p>\n<pre>#this grabs stuff from my friend's repo\r\ngit fetch friend<\/pre>\n<p>Specifying &#8220;friend&#8221; is necessary, because git will pull by your default repo if one is not specified (and your default is probably &#8220;origin&#8221;).  At this point, we can track the branch and merge.<\/p>\n<pre>git merge friend\/master\r\n<\/pre>\n<p>Summary:<\/p>\n<pre>git remote add friend \/path\/to\/other\/repo\r\ngit fetch friend\r\ngit merge friend\/master\r\n<\/pre>\n<p>It&#8217;s actually pretty simple. It might even be obvious, provided you already understand the way git works.  Otherwise, you might find this useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m working with others on a paper written in LaTeX.\u00a0 It&#8217;s stored in a git repository.\u00a0 I figured it would be easy for all of us to track and merge each other&#8217;s changes this way.\u00a0 So my friend clones the &hellip; <a href=\"https:\/\/imperfectcode.com\/?p=14\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/imperfectcode.com\/index.php?rest_route=\/wp\/v2\/posts\/14"}],"collection":[{"href":"https:\/\/imperfectcode.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imperfectcode.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imperfectcode.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/imperfectcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":1,"href":"https:\/\/imperfectcode.com\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":15,"href":"https:\/\/imperfectcode.com\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions\/15"}],"wp:attachment":[{"href":"https:\/\/imperfectcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imperfectcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imperfectcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}