README.md 2.93 KB
Newer Older
Hugo Buddelmeijer's avatar
Hugo Buddelmeijer committed
1
2
# gitremotesync

Hugo Buddelmeijer's avatar
Hugo Buddelmeijer committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Sync the master branches of the local repository and all remotes.

E.g. running this in a git repository with these remotes, will synchronize
three repositories:
```shell script
$ git remote -v
github  git@github.com:hugobuddel/testlatex2.git (fetch)
github  git@github.com:hugobuddel/testlatex2.git (push)
gitlab  git@gitlab.astro-wise.org:buddel/testlatex2.git (fetch)
gitlab  git@gitlab.astro-wise.org:buddel/testlatex2.git (push)
overleaf        https://git.overleaf.com/5ef9e60ebb7def000199c1c5 (fetch)
overleaf        https://git.overleaf.com/5ef9e60ebb7def000199c1c5 (push)
```

These projects will be synchronized:
* https://www.overleaf.com/project/5ef9e60ebb7def000199c1c5
* https://gitlab.astro-wise.org/buddel/testlatex2
* https://github.com/hugobuddel/testlatex2

Any change to master of one of these projects will propagate to the others.
This will allow seamless collaboration through overleaf, github and/or gitlab.

Collaborators who prefer to use merge/pull requests can do so through gitlab
or github. These changes will seem like an extremely fast typer to the
collaborators that are using overleaf. Vice versa, overleaf users appear
as people who create many commits to the gitlab/github users.

To run this script, clone one of the repositories,
add the other remotes, then run the script.
```shell script
git clone git@gitlab.astro-wise.org:buddel/gitremotesync.git
git clone git@gitlab.astro-wise.org:buddel/testlatex2.git
cd testlatex2
git init
git remote rename origin gitlab
git remote add overleaf https://git.overleaf.com/5ef9e60ebb7def000199c1c5
git remote add github git@github.com:hugobuddel/testlatex2.git
bash ../gitremotesync/synchronize.sh
``` 

Two things that you need to do that are beyond the scope of this project:
* Cache your overleaf credentials, it is not possible to use SSH for overleaf.
* Run the script periodically, e.g. every minute or before and after each change
  you want to make.
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

## Initial setup

Overleaf does some strange things with git. E.g. it deletes all the history
when importing a project, but creates a history when creating a new project.

Therefore some special instructions need to be followed to initially setup
the linked projects.

### Setup from existing GitLab repository

First create a new blank project. Do not import a project. Choose 'git' in the
'Sync' menu and copy the url (but note the `git clone` part). It should look
like https://git.overleaf.com/5efb2cbe8306d30001f4cba8.

```shell script
git clone git@gitlab.astro-wise.org:buddel/testlatex2.git
cd testlatex2
git remote rename origin gitlab
git remote add overleaf https://git.overleaf.com/5efb2cbe8306d30001f4cba8
git fetch overleaf
git merge -X ours overleaf/master
git push overleaf master
git push gitlab master
```

### Setup from existing Overleaf repository
This is simpler, just create an empty project on GitLab (that is, do not
initialize with a readme), clone the Overleaf repository like usual, add
the GitLab remote and push there.