<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>weblog.masukomi.org - configuration</title>
    <subtitle>Autistic, ADHD, Geek. The weblog of Kay Rhodes (masukomi).</subtitle>
    <link rel="self" type="application/atom+xml" href="https://weblog.masukomi.org/tags/configuration/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://weblog.masukomi.org"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2013-01-31T00:00:00+00:00</updated>
    <id>https://weblog.masukomi.org/tags/configuration/atom.xml</id>
    <entry xml:lang="en">
        <title>Git: pushing and pulling from multiple repos</title>
        <published>2013-01-31T00:00:00+00:00</published>
        <updated>2013-01-31T00:00:00+00:00</updated>
        
        <author>
          <name>Kay Rhodes</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://weblog.masukomi.org/2013/01/31/git-pushing-and-pulling-from-multiple-repos/"/>
        <id>https://weblog.masukomi.org/2013/01/31/git-pushing-and-pulling-from-multiple-repos/</id>
        
        <content type="html" xml:base="https://weblog.masukomi.org/2013/01/31/git-pushing-and-pulling-from-multiple-repos/">&lt;p&gt;Lets assume you’ve already cloned a remote repo and have been working with it. Now, someone has set up a second repo out there for the same codebase, and you’d like to interact with both.&lt;/p&gt;
&lt;p&gt;*Please note: The following is based on the assumption that you have write privileges to the second repo, but don’t worry, you do essentially the same thing if you don’t and I’ll cover the differences at the end. *&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;git remote add &amp;lt;local_name_for_remote_repo&amp;gt; &lt;url&gt;&lt;/li&gt;
&lt;li&gt;git checkout -b &lt;branch name&gt; &amp;lt;local_name_for_remote_repo&amp;gt;/master
&lt;ul&gt;
&lt;li&gt;could be any branch on that repo, not necessarily master&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now, your new local branch is now set up to track (push and pull to/from) the remote repo’s “master” branch. All your pre-existing branches will continue to track whatever they were tracking previously&lt;/p&gt;
&lt;p&gt;A practical example:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git remote add repo2  git@github.com:masukomi/kudos.git&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git checkout -b repo2_kudos -t repo2/master&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;workflow&quot;&gt;Workflow&lt;/h2&gt;
&lt;p&gt;Let’s say you’ve decided to add a new feature in the &lt;code&gt;kudos&lt;/code&gt; repo we just connected to.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Checkout the &lt;code&gt;repo2_kudos&lt;/code&gt; branch&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git pull&lt;/code&gt; to get the latest code from repo2/master&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git checkout -b adding_feature_x&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;this new topic branch is not &lt;em&gt;yet&lt;/em&gt; tracking anything so if you attempt to &lt;code&gt;push&lt;/code&gt; or &lt;code&gt;pull&lt;/code&gt; it won’t work, because it won’t know what endpoint you want to interact with.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Make your changes on this topic branch.&lt;/li&gt;
&lt;li&gt;When you’re ready run &lt;code&gt;git push -u repo2 adding_feature_x&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;This will do three things:
&lt;ol&gt;
&lt;li&gt;It will create a new branch in the repo2 repository named “adding_feature_x”&lt;/li&gt;
&lt;li&gt;It will push the contents of your &lt;code&gt;adding_feature_x&lt;/code&gt; branch into the corresponding one on repo2.&lt;/li&gt;
&lt;li&gt;It will configure things so that your local &lt;code&gt;adding_feature_x&lt;/code&gt; branch is now tracking the remote &lt;code&gt;adding_feature_x&lt;/code&gt; branch so &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;pull&lt;/code&gt; will work without additional arguments. &lt;strong&gt;You &lt;em&gt;must&lt;/em&gt; pass the &lt;code&gt;-u&lt;/code&gt; parameter for tracking to be set up here.&lt;/strong&gt; If you fail to pass the &lt;code&gt;-u&lt;/code&gt; parameter at this point then &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;pull&lt;/code&gt; won’t work without additional parameters. You can, however, set up tracking after the fact with &lt;code&gt;git branch -u repo2/adding_feature_x&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now that you’ve pushed your changes to the new branch on the remote repo you can initiate pull requests from your topic branch into the main branches (if you’re using github) or you can simple tell others about it so that they can interact with it.&lt;/p&gt;
&lt;p&gt;Keep in mind that it’s best practice to regularly pull from your main branch into your topic branch (&lt;code&gt;repo2_kudos&lt;/code&gt; into &lt;code&gt;adding_feature_x&lt;/code&gt; in this case) so as to avoid large merge conflicts. Alternately you could pull from the corresponding main branch on the second repo (&lt;code&gt;repo2/master&lt;/code&gt; in this case) since they should be equivalent.&lt;/p&gt;
&lt;h2 id=&quot;when-you-don-t-have-write-privileges&quot;&gt;When you don’t have write privileges&lt;/h2&gt;
&lt;p&gt;If you don’t have write privileges to the second repo things change slightly. The difference is in where you push your new topic branch (&lt;code&gt;adding_feature_x&lt;/code&gt;) to. You can either push as a new branch on whatever repo your local repo was cloned from (if you’ve got write privileges to that) &lt;em&gt;or&lt;/em&gt; you can create a third remote repo that you control, and push the branch to that. The third repo would be configured in the same way as the second, and you should be able to push to it in the same way we pushed to the second. Git makes it easy to flow code from one repo to another, or through multiple repos.&lt;/p&gt;
</content>
        
    </entry>
</feed>
