20

In a local gitlab I created a copy of project nova (https://github.com/openstack/nova).

How do I keep the local nova repo in sync with github, updating maybe once per hour or per day?

I would like a solution similar to what is described here for bitnami: http://wiki.bitnami.com/Applications/BitNami_GitLab#Keeping_in_sync_with_the_GitLab_repository_at_GitHub

(I used Devstack to install Openstack.)

ajm475du
  • 103
  • 2
user186107
  • 197
  • 1
  • 1
  • 4
  • Perhaps you could change `How do I keep the local nova repo in sync with github` to: `How do I keep a GitLab copy/mirror of the nova repo in sync with the original repo in GitHub`. That may reduce some ambiguity. For example, that change would render the answer by @DennisKaarsemaker becomes invalid/inappropriate, because that answer keeps a local repository in sync, whereas your question title seems to ask how you can sync the repository in Gitlab instead of locally. – a.t. Sep 17 '21 at 11:44

5 Answers5

10

GitLab now has this feature built-in!
Since GitLab EE 8.2 it's supported. Hooray!

Pulling from a remote respository

You can set up a repository to automatically have its branches, tags, and commits updated from an upstream repository.
...

When creating a new project, you can enable repository mirroring when you choose to import the repository from "Any repo by URL". Enter the full URL of the Git repository to pull from and click on the Mirror repository checkbox.

GitLab auto mirroring
(source: gitlab.com)

>

For an existing project, you can set up mirror pulling by visiting your project's Settings ➔ Repository and searching for the "Pull from a remote repository" section. Check the "Mirror repository" box and hit Save changes at the bottom.
...

Glorfindel
  • 1,213
  • 3
  • 15
  • 22
arieljannai
  • 225
  • 1
  • 3
  • 9
  • 1
    Their example uses gitlab, I followed it exactly except replaced that part with Github, and the updating thing never finishes... – MarcusJ Jul 13 '17 at 20:36
  • @MarcusJ Exactly the same here, did you find a solution? – MemphiZ Nov 02 '18 at 11:25
  • It's been a while since I had to do this, but I think what I did was use the ssh url in the format of ssh://git@gitlab.com:UserName:RepoName.git – MarcusJ Nov 02 '18 at 21:49
  • I just made this work, pulling from github to gitlab is easy if your repo is public, just paste this URL in gitlab settings: `https://github.com/yourGithubUserName/repoName.git`, then choose the Password method in the combobox and leave the password textbox blank – knocte Jun 05 '19 at 11:32
5

If you never need local commits, the following recipe will work:

Clone the repo with --mirror:

git clone --mirror https://github.com/openstack/nova.git

Then in a cronjob, you do this for an hourly update:

0 * * * * cd /path/to/nova.git && git fetch

The --mirror sets up the refspecs in such a way that subsequent fetches will update all local refs, so you don't need to merge the changes in. Of course that does mean that commits pushed to that repo are lost.

Dennis Kaarsemaker
  • 18,793
  • 2
  • 43
  • 69
3

I wrote a project with the intention of adding remote mirrors to GitLab. You can check it out here...

https://github.com/sag47/gitlab-mirrors

Sam Gleske
  • 171
  • 5
0

Create a cron job to update the repo

Drew Khoury
  • 4,569
  • 8
  • 26
  • 28
0

You can do this using cron jobs.

In your terminal type crontab -e (to edit your crontab) and add a new line at the bottom with the following.

* 0 * * * git clone ssh://username@hostname:port/repo

It will run a clone every day at midnight.

Falcon Momot
  • 24,975
  • 13
  • 61
  • 92
Sohan
  • 729
  • 1
  • 6
  • 12