Browse Source

Explain how to use multiple remote tracking URLs to mirror a repo

master
Andreas Linz 3 years ago
parent
commit
8ac4b33726
Signed by: alinz GPG Key ID: 9BF39809C9DA580C
1 changed files with 7 additions and 2 deletions
  1. +7
    -2
      how-to-mirror-a-git-repository.md

+ 7
- 2
how-to-mirror-a-git-repository.md View File

@ -4,8 +4,13 @@ Most git providers allow to mirror a remote repository but the biggest one of al
So, how do you mirror a repository to github then?
I think the easiest and most straightforward way is to specify a git-hook to do exactly this.
First specify both remotes, in my chase those are `git remote add <origin> <repo-URL>` and `git remote add <mirror> <repo-URL>`.
Now create the hook: `$ echo 'git push --force --mirror <mirror>' > .git/hooks/post-commit'.
The next time you push your changes into `<origin>` the changes will be automatically mirrored into `<mirror>`.
~~Now create the hook: `$ echo 'git push --force --mirror <mirror>' > .git/hooks/post-commit'.
The next time you push your changes into `<origin>` the changes will be automatically mirrored into `<mirror>`.~~
Forget the idea to use git hooks, first I forgot to make the hook executable and second it was the wrong type, instead of `post-commit` I had to use `pre-push`. Nonetheless, it won't work that way.
But, luckily there are is another apporach that is simply adding another push URL to the remote.
`$ git remote set-url --add <origin> <mirror-URL>`
Voila!
More information about git hooks can be found in `man githooks` and usually there is a bunch of sample files in `.git/hooks`.

Loading…
Cancel
Save