Seite wählen

Sync Git repositories to GitHub

von | Dez 11, 2014 | Technology

GitHub-Mark-120px-plusWhile we still have our own repositories located at https://git.netways.org it’s reasonable to sync the existing repositories to GitHub targetting a wider audience (and not everyone likes the gitorious web interface either). There are certain requirements syncing git repositories in general:

  • create, update and delete branches
  • create and delete tags
  • don’t always clone the repository but fetch local changes

Aside from that, you’ll need

  • a shell user, e.g. github on a box running the sync
  • ssh key for pushing remote origin
  • small sync script
  • a cronjob for that sync script, e.g. every 5 minutes
  • git binary >= 1.7.10 providing the –prune option

If you are planning to push your local repository (in our example, git.netways.org) to github.com, you’ll also need the following

  • add the public ssh key to your github user at https://github.com/settings/ssh
  • ensure that this user is allowed to push your company’s repositories (make it a team member)

The sync script part is easy thanks to the possibilities git already provides. An older version of the sync script is used for syncing the Icinga Github repositories in a similar fashion. For Icinga, it’s most important to sync the git tags, making the release tarballs available on Github.

#!/bin/bash
REPO_HOME="/data/scm/sync"
declare -A REPOS
# syntax is [github_repo]="netways_repo"
REPOS=([ingraph]="ingraph/ingraph" [lconf]="lconf/lconf" [lconf-icinga-module]="lconf/icinga-module" [lconf-web]="lconf/lconf-web")
cd $REPO_HOME
for REPO_GITHUB in "${!REPOS[@]}"
do
	REPO_LOCAL=${REPOS[$REPO_GITHUB]}
        echo "### Processing repo $REPO_LOCAL"
        if [ ! -d $REPO_LOCAL ]; then
                git clone --bare --mirror git://git.netways.org/$REPO_LOCAL.git $REPO_LOCAL
        fi
        (cd $REPO_LOCAL; git fetch --prune; git push --prune git@github.com:NETWAYS/$REPO_GITHUB.git +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*)
done

git {fetch,push} –prune ensures that deleted branches/tags on the source repository are also deleted on the target repository.
Saving the sync script as /data/scm/sync/create_and_sync allows you to add the following cron job every five minutes:

# su - github
$ crontab -e
# Sync repos to github
*/5 * * * * /data/scm/sync/create_and_sync > /dev/null 2>&1

Ynetways_githubou can check the result watching the development branches at https://github.com/netways for LConf and inGraph – if you’re looking for your own custom git integration, don’t hesitate to contact us 🙂
PS: Another cool way of syncing github repositories is the Icinga Exchange integration!

0 Kommentare

Trackbacks/Pingbacks

  1. Wellenreiten 12/2014 | Netz - Rettung - Recht - […] Friedrich bei Netways: Sync Git repositories to GitHub Synchronisation eigener Git-Repositories mit Repositories bei […]

Einen Kommentar abschicken

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Mehr Beiträge zum Thema Technology

Kibana Sicherheits-Updates: CVSS:Critical

Und täglich grüßt das Murmeltier. Nein nicht ganz. Heute ist es  aus der Elastic Stack Werkzeugkiste Kibana, für das es ein wichtiges Sicherheits-Update gibt. Es besteht auf jeden Fall Handlungsbedarf! IMHO auch wenn ihr die "Reporting" Funktion deaktiviert habt. Der...