Git local mirror and repository -


here do:

  • have local git repository mirrors upstream one
  • be able push "local" branches / changes repository , keep locally
  • keep repository in sync upstream one, including:
    • fetch new branch
    • delete reference of branches deleted upstream

i setup cron job fetch changes upstream , prune branch have been deleted this:

*/5 * * * * cd /home/git/myrepo.git && git fetch origin && git remote prune origin > /dev/null 

so far have tried (and why failed):

1- setup git repository mirror (as described here)

git clone --bare --mirror url 

the problem when git remote prune, deleting references "local" changes have been pushed there (and not upstream server).

i tried have local repository mirror 2 separate repositories (with same master different branches) , hit similar problem when doing git remote prune, delete branches coming other repository.

2- setup git bare repository:

git clone --bare url 

but git fetch origin not updating properly, seems downloading objects, not create refs , prints

 * branch            head       -> fetch_head 

and "location" of current branches not being updated what's in upstream server.

i tried git remote update described here, same result.

i can convert repository mirror with:

git config remote.origin.fetch 'refs/heads/*:refs/heads/*' 

but brings me problem in (1)

assuming can drop "mirror" requirement, , have "local (bare) repo $x copies upstream repo $ux using refs/heads/upstream/$branch name upstream branches known there refs/heads/$x", use second approach, instead:

$ cd /tmp; mkdir tt; cd tt; git clone --bare ssh://$upstream_host/tmp/t $ cd t.git $ git config remote.origin.fetch '+refs/heads/*:refs/heads/upstream/*' $ git fetch -p # accidentally omitted step cut/paste earlier 

this assumes won't use branch names upstream/master yourself. (you also/instead like:

git config remote.origin.fetch '+refs/*:refs/upstream/*' 

but refs/upstream/* references not copied on normal git clone, git fetch, etc., more of pain "normal" git users.)

let's make clone of --bare repo see happens go on. (for reference, on $upstream_host, have /tmp/t, regular git repo. on $local_host, not-quite-mirror machine, have /tmp/tt/t.git, --bare repo upstream tracking thing. using same host both principle applies...)

$ cd /tmp; mkdir xt; cd xt; git clone ssh://$local_host/tmp/tt/t.git cloning 't'... remote: counting objects: 96, done. remote: compressing objects: 100% (54/54), done. remote: total 96 (delta 33), reused 96 (delta 33) receiving objects: 100% (96/96), 17.11 kib | 0 bytes/s, done. resolving deltas: 100% (33/33), done. checking connectivity... done 

now made change on $upstream_host in /tmp/t, , commited it. on $local_host:

$ cd /tmp/tt/t.git; git fetch -p origin # -p prune deleted upstream/foo's remote: counting objects: 5, done. remote: compressing objects: 100% (4/4), done. remote: total 4 (delta 1), reused 0 (delta 0) unpacking objects: 100% (4/4), done. ssh://$host/tmp/t  + c10e54c...5e01371 master     -> upstream/master  (forced update) 

thus, changes made upstream appear in "sort of mirror not exactly" bare git repo change upstream/master rather master, or more generally, upstream/$branch $branch. if want merge them you'll have manually. example below bit messy because change made on $upstream_host history rewrite (hence forced update stuff), winds getting exposed here via clones. if don't want exposed you'll have note updates history rewrites , (in effect) manually copy them own not-quite-mirror, , on clones of that. i'll go ahead , make real merge.

so, go non-bare repo on $local_host, in /tmp/xt/t:

$ cd /tmp/xt/t $ git fetch remote: counting objects: 5, done. remote: compressing objects: 100% (4/4), done. remote: total 4 (delta 1), reused 1 (delta 0) unpacking objects: 100% (4/4), done. ssh://$local_host/tmp/tt/t  + c10e54c...5e01371 upstream/master -> origin/upstream/master  (forced update) $ git status # on branch master nothing commit, working directory clean $ git log --oneline --decorate --graph * 5e01371 (origin/upstream/master) add ast example | * c10e54c (head, origin/master, origin/head, master) add ast example |/   * 309b36c add like_min.py ... [snipped] $ git merge origin/upstream/master  merge remote-tracking branch 'origin/upstream/master'  # please enter commit message explain why merge necessary, # if merges updated upstream topic branch. # # lines starting '#' ignored, , empty message aborts # commit. ... $ git push warning: push.default unset; implicit value changing in git 2.0 'matching' 'simple'. squelch message ... counting objects: 1, done. writing objects: 100% (1/1), 244 bytes | 0 bytes/s, done. total 1 (delta 0), reused 0 (delta 0) ssh://$local_host/tmp/tt/t.git    c10e54c..e571182  master -> master 

i've updated --bare clone ($local_host, /tmp/tt/t.git) via non-bare clone merge upstream work local not-exactly-a-mirror. head revision merge, head^1 original (broken) update used origin/upstream/master (before "forced update"ing), , head^2 corrected update origin/upstream/master (afterward):

$ git rev-parse head^2 origin/upstream/master 5e013711f5d6eb3f643ef562d49a131852aa4aa1 5e013711f5d6eb3f643ef562d49a131852aa4aa1 

(the name upstream/master in --bare clone, git rev-parse above /tmp/xt/t not /tmp/tt/t.git.)


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -