Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of copying the ref files around (bad bad!) use <code>git update-ref</code></p> <p>Note that you can have what you wanted pretty easily to a bare repository when pushing instead of pulling.</p> <p>Use this:</p> <pre><code> git clone --mirror . /tmp/bareclone </code></pre> <p>to create the bare repository that you want to keep completely in synch Now, to synch all the branches to the bareclone mirror, use</p> <pre><code> git push /tmp/bareclone --mirror </code></pre> <p>NOTE that this will also remove any heads that aren't in the source repo but (still) are in the bareclone. Also note that you can use send-pack instead of push there because this interface is rather lowlevel and actually implemented by send-pack</p> <p>HTH</p> <hr> <p>As the commenter noted, I slighly avoided the subject that it doesn't seem possible at once to do the inverse. However, you can get a long ways towards the goal by doing something slightly advanced like:</p> <h3>1. Simple, safe and pretty unexciting.</h3> <pre><code>git fetch $url -- $(git ls-remote -h $url | while read sha ref; do echo "$ref:refs/remotes/fetched/${ref#refs/heads/}"; done) </code></pre> <p>Set `url=git://your.server/project.git' e.g. </p> <p>I made sure that the refs are created in a moderately safe location. The effect very similar to doing.</p> <pre><code>git remote add fetched $url --fetch </code></pre> <p>So there is nothing much, <em>but</em> it shows you how to use plumbing commands to achieve it, so we can now adapt them to our needs:</p> <h3>2. Fetch directly into local branches (heads)</h3> <p>Now <strong>if you are sure you know what you're doing</strong> you can use the following style to get the branches duplicated locally:</p> <pre><code>git init --bare . git fetch $url -- $(git ls-remote -h $url | while read sha ref; do echo "$ref:$ref"; done) </code></pre> <blockquote> <p><sub><strong>Note</strong>: if you want to <em>force</em> update (e.g. when there is no fast-forward pull because of an upstream rebase, reset, filter-branch, or amended commit (in general -- any rewritten history) replace <code>echo "$ref:$ref"</code> by <code>echo "+$ref:$ref"</code></sub>; (Thanks <a href="https://stackoverflow.com/users/449215/dov-grobgeld">Dov</a>)</p> </blockquote> <h3>3. The full monty</h3> <p>This could also be combined, so you can have a remote definition too. <em>I'd recommend that because it will mean that the local branches are actually tracking the ones from the remotes, and you'll have better insulation/recovery options if you accidentally clobber some of the local commits on these branches with these powerful fetch commands</em></p> <pre><code>git init --bare . git remote add fetched $url --fetch git for-each-ref --format='%(refname:short)' -- 'refs/remotes/fetched/' | while read ref; do git branch -t "$(basename "$ref")" "$ref"; done </code></pre> <p>Have fun, HTH</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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