# Synchroniser 2 dépôts (--bare):



ssh://bruno@clicclac.synology.me:42666/volume1/Repositories/wp_yuzu-child.git

bruno@maboiteverte.fr:~/git/wp_yuzu-child.git

```bash
$ git clone --mirror ssh://bruno@clicclac.synology.me:42666/volume1/Repositories/wp_yuzu-child.git

$ cd wp_yuzu-child.git
total 16
-rw-r--r--  1 bruno staff  23 May  8 09:13 HEAD
-rw-r--r--  1 bruno staff 253 May  8 09:13 config
-rw-r--r--  1 bruno staff  73 May  8 09:13 description
drwxr-xr-x 14 bruno staff 448 May  8 09:13 hooks
drwxr-xr-x  3 bruno staff  96 May  8 09:13 info
drwxr-xr-x  4 bruno staff 128 May  8 09:13 objects
-rw-r--r--  1 bruno staff 105 May  8 09:13 packed-refs
drwxr-xr-x  4 bruno staff 128 May  8 09:13 refs

$ nano config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = ssh://bruno@clicclac.synology.me:42666/volume1/Repositories/wp_yuzu-child.git
        fetch = +refs/*:refs/*
        mirror = true

```

On ajoute le second dépôt distant:

```bash
$ git remote add --mirror=fetch secondary ssh://bruno@maboiteverte.fr:~/git/wp_yuzu-child.git

$ nano config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = ssh://bruno@clicclac.synology.me:42666/volume1/Repositories/wp_yuzu-child.git
        fetch = +refs/*:refs/*
        mirror = true
[remote "secondary"]
        url = bruno@maboiteverte.fr:~/git/wp_yuzu-child.git
        fetch = +refs/*:refs/*
```

On récupère les commits et refs du 1er dépôt (origin):

```bash
$ git fetch origin

$ l
total 20
-rw-r--r--  1 bruno staff 142 May  8 09:25 FETCH_HEAD		<-
-rw-r--r--  1 bruno staff  23 May  8 09:13 HEAD
-rw-r--r--  1 bruno staff 357 May  8 09:18 config
-rw-r--r--  1 bruno staff  73 May  8 09:13 description
drwxr-xr-x 14 bruno staff 448 May  8 09:13 hooks
drwxr-xr-x  3 bruno staff  96 May  8 09:13 info
drwxr-xr-x  4 bruno staff 128 May  8 09:13 objects
-rw-r--r--  1 bruno staff 105 May  8 09:13 packed-refs
drwxr-xr-x  4 bruno staff 128 May  8 09:13 refs

$ nano FETCH_HEAD
e3bd4d1ce81a2a0c6f87f713ec7a84ae4327c87a        not-for-merge   branch 'master' of ssh://clicclac.synology.me:42666/volume1/Repositories/wp_yuzu-child
```

On met à jour le second dépôt (avec local refs)

```bash
$ git push secondary --all
Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (42/42), 529.85 KiB | 88.31 MiB/s, done.
Total 42 (delta 16), reused 42 (delta 16), pack-reused 0
remote:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
remote:                                  Dload  Upload   Total   Spent    Left  Speed
remote:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
To maboiteverte.fr:~/git/wp_yuzu-child.git
 * [new branch]      master -> master
```

On vérifie sur le second dépôt:

```bash
bruno@localhost:~/git/wp_yuzu-child.git$ l
total 40
drwxr-xr-x  7 bruno psacln 4096 May  8 09:39 .
drwxr-xr-x  5 bruno psacln 4096 May  8 08:47 ..
drwxr-xr-x  2 bruno psacln 4096 May  8 08:47 branches
-rw-r--r--  1 bruno psacln   66 May  8 08:47 config
-rw-r--r--  1 bruno psacln   73 May  8 08:47 description
-rw-r--r--  1 bruno psacln   23 May  8 09:39 HEAD						<-
drwxr-xr-x  2 bruno psacln 4096 May  8 08:47 hooks
drwxr-xr-x  2 bruno psacln 4096 May  8 08:47 info
drwxr-xr-x 43 bruno psacln 4096 May  8 09:39 objects				<-
drwxr-xr-x  4 bruno psacln 4096 May  8 08:47 refs
```

Les 2 dépôts ont maintenant les mêmes fichiers et historiques.



A partir de la, pour maintenir les 2 dépôts synchronisés:

- un nouveau commit est crée sur le 1er dépôt:

  ```bash
  $ git fetch origin
  $ git push secondary --all
  ```

- un nouveau commit est crée sur le 2nd dépôt:

  ```bash
  $ git fetch secondary
  $ git push origin
  ```

- les 2 dépôts sont modifiés:

  ```bash
  # mkdir ../workdir
  # git fetch origin
  # git --work-tree=../workdir/ checkout branch_name file_name1
  # git fetch secondary
  # git --work-tree=../workdir/ checkout branch_name file_name2
  # git push secondary
  # git push origin
  ```

  

