Skip to content

Instantly share code, notes, and snippets.

@ksarmalkar
Created July 3, 2014 04:11
Show Gist options
  • Save ksarmalkar/56ebd935403ebe909dcd to your computer and use it in GitHub Desktop.
Save ksarmalkar/56ebd935403ebe909dcd to your computer and use it in GitHub Desktop.
How to host maven repo on GitHub ?

The first step is to create a separate clone of your GitHub repository in a directory next to your primary local repository:

$ pwd
/Users/ksarmalkar/workspace/Android-ViewPagerIndicator
$ cd ..
$ git clone [email protected]:ksarmalkar/Android-ViewPagerIndicator.git Android-ViewPagerIndicator-Pages
$ cd Android-ViewPagerIndicator-Pages

The GitHub Pages web site must be created as a branch named gh-pages in your repository. So lets create this branch and empty it. Refer to the GitHub Pages Manual if you are interested in the exact meaning of these commands.

$ git symbolic-ref HEAD refs/heads/gh-pages
$ rm .git/index
$ git clean -fdx

We will place the Maven repository in a subdirectory of this new branch:

$ mkdir maven

Now Upload your repo to maven/ folder in above case /Users/ksarmalkar/workspace/Android-ViewPagerIndicator-Pages/maven

We also want to have a pretty directory listing. Unfortunately GitHub Pages doesn't have native support for this. So we will create our own directory listing with a simple bash script. Refer update-directory-index.sh. Place this file in /Users/ksarmalkar/workspace/Android-ViewPagerIndicator-Pages/maven once you uplaod your maven artifacts here run ./update-directory-index.sh.

Then push all the files in the branch gh-pages to GitHub.

#!/bin/bash
for DIR in $(find ./repository -type d); do
(
echo -e "<html>\n<body>\n<h1>Directory listing</h1>\n<hr/>\n<pre>"
ls -1pa "${DIR}" | grep -v "^\./$" | grep -v "index.html" | awk '{ printf "<a href=\"%s\">%s</a>\n",$1,$1 }'
echo -e "</pre>\n</body>\n</html>"
) > "${DIR}/index.html"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment