Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two separate problems here:</p> <ol> <li>How do you maintain local forks of remote projects, and</li> <li>How do you keep a copy of remote projects in your own tree?</li> </ol> <p>Problem 1 is pretty easy by itself. Just do something like:</p> <pre><code>git clone git://example.com/foo.git cd foo git remote add upstream git://example.com/foo.git git remote rm origin git remote add origin ssh://.../my-forked-foo.git git push origin </code></pre> <p>You can then work on your forked repository normally. When you want to merge in upstream changes, run:</p> <pre><code>git pull upstream master </code></pre> <p>As for problem 2, one option is to use submodules. For this, cd into your main project, and run:</p> <pre><code>git submodule add ssh://.../my-forked-foo.git local/path/for/foo </code></pre> <p><strong>If I use git submodules, what do I need to know?</strong></p> <p>You may find git submodules to be a little bit tricky at times. Here are some things to keep in mind:</p> <ol> <li>Always commit the submodule before committing the parent.</li> <li>Always push the submodule before pushing the parent.</li> <li>Make sure that the submodule's HEAD points to a branch before committing to it. (If you're a bash user, I recommend using <a href="http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-without" rel="noreferrer">git-completion</a> to put the current branch name in your prompt.)</li> <li><em>Always</em> run 'git submodule update' after switching branches or pulling changes.</li> </ol> <p>You can work around (4) to a certain extent by using an alias created by one of my coworkers:</p> <pre><code>git config --global alias.pull-recursive '!git pull &amp;&amp; git submodule update --init' </code></pre> <p>...and then running:</p> <pre><code>git pull-recursive </code></pre> <p><strong>If git submodules are so tricky, what are the advantages?</strong></p> <ol> <li>You can check out the main project without checking out the submodules. This is useful when the submodules are huge, and you don't need them on certain platforms.</li> <li>If you have experienced git users, it's possible to have multiple forks of your submodule, and link them with different forks of your main project.</li> <li>Someday, somebody might actually fix git submodules to work more gracefully. The deepest parts of the submodule implementation are actually quite good; it's just the upper-level tools that are broken.</li> </ol> <p><strong>git submodules aren't for me. What next?</strong></p> <p>If you don't want to use git submodules, you might want to look into <a href="http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html" rel="noreferrer">git merge's subtree strategy</a>. This keeps everything in one repository.</p> <p><strong>What if the upstream repository uses Subversion?</strong></p> <p>This is pretty easy if you know how to use git svn:</p> <pre><code>git svn clone -s https://example.com/foo cd foo git remote add origin ssh://.../my-forked-foo.git git push origin </code></pre> <p>Then set up a local tracking branch in git.</p> <pre><code>git push origin master:local-fork git checkout -b local-fork origin/local-fork </code></pre> <p>Then, to merge from upstream, run:</p> <pre><code>git svn fetch git merge trunk </code></pre> <p>(I haven't tested this code, but it's more-or-less how we maintain one submodule with an upstream SVN repository.)</p> <p>Don't use git svn rebase, because it will make it very difficult to use git submodule in the parent project without losing data. Just treat the Subversion branches as read-only mirrors of upstream, and merge from them explicitly.</p> <p>If you need to access the upstream Subversion repository on another machine, try:</p> <pre><code>git svn init -s https://example.com/foo git svn fetch </code></pre> <p>You should then be able to merge changes from upstream as before.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload