Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't I push from a shallow clone?
    primarykey
    data
    text
    <p>The <code>git clone --depth</code> command option says</p> <pre><code>--depth &lt;depth&gt; Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches. </code></pre> <p>Why do shallow clones have this limitation? Why is it a patches only workflow?</p> <p>For some project workflows I need to pass just the latest commit from a single branch to a coder, and then have them be able to <code>push</code> their (fast forward) developments to the main server. This partly for security, IP protection and repo size, and partly to reduce the confusion that a big repo would bring to a naive coder. Is there a git workflow that allows this?</p> <hr> <p>Update: Based on Karl Bielefeldt's answer the <code>git checkout --orphan</code> should be the right answer. But one still needs to 'clone' that branch alone to the new user, and be able to push it effectively.</p> <p>The man page states:</p> <blockquote> <p><code>git checkout [-q] [-f] [-m] [[-b|-B|--orphan] &lt;new_branch&gt;] [&lt;start_point&gt;] --orphan</code></p> <p>Create a new orphan branch, named <code>&lt;new_branch&gt;</code>, started from <code>&lt;start_point&gt;</code> and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.</p> <p>The index and the working tree are adjusted as if you had previously run <code>git checkout &lt;start_point&gt;</code>. This allows you to start a new history that records a set of paths similar to <code>&lt;start_point&gt;</code> by easily running <code>git commit -a</code> to make the root commit.</p> <p>This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.</p> <p>If you want to start a disconnected history that records a set of paths that is totally different from the one of <code>&lt;start_point&gt;</code>, then you should clear the index and the working tree right after creating the orphan branch by running <code>git rm -rf .</code> from the top level of the working tree. Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.</p> </blockquote> <p>VonC's link to Junio's comments is interesting. I think the manual should provide the guidance in this case, and allow the right command [e.g. <code>clone &lt;branch&gt; --options</code>] to extract just the relevant part of the repo. Obviously the probability of <code>push</code> success is increased by having a few linked commits and SHA1s at the bottom of the history that will lock down the repo matching.</p> <hr> <p>Update Git 1.9.0 : release notes 14 Feb '14.</p> <p>"Fetching from a shallowly-cloned repository used to be forbidden, primarily because the codepaths involved were not carefully vetted and we did not bother supporting such usage. This release attempts to allow object transfer out of a shallowly-cloned repository in a more controlled way (i.e. the receiver becomes a shallow repository with a truncated history)."</p> <p>This is good news for the shallow cloners. Next - Narrow clones possibly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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