How to integrate a GitHub wiki into the main project

Viewed 10406

I want keep all my source code and documentation in one single git repository. I already have the github pages integrated into my main project and now I want to do the same with the github wiki.

I know that github wikis are plain git repositories. My plan is to add the wiki as a remote to my main repo and keep everything in one place. However in the wiki repo everything is in the root directory and thus would clutter my main project.

Has anyone tried this before? What is the best way to handle this?

4 Answers

You could place a copy of a wiki repository into your main repository and work with them in parallel:

$ git init
$ git remote add -m master origin git@github.com:<owner>/<repo>.git
$ git add .
$ git commit -m 'Initial commit'
$
$ cd wiki
$ git init
$ git remote add -m master origin git@github.com:<owner>/<repo>.wiki.git
$ git add .
$ git commit -m 'Initial wiki commit'
$
$ git push -uf origin master
$ cd ..
$ git push -u origin master

This method kinda combines the pros of submodules and subtrees suggested in other answers, but doesn't complicate the workflow much: it allows you to have wiki files in your main repository, see them in pull requests and easily push them to or pull from the wiki.

To add a contents of an existing repository into another repository you'll need to remove the .git folder for a while (otherwise Git will add it as a submodule):

$ mv wiki/.git/ wiki/.git__/ && git add wiki/* && mv wiki/.git__/ wiki/.git/

This is only a one-time issue, any future files can be added as usual.

Note that the .git folder of a wiki repository won't be included into your main repository.
This answer describes how to restore it after cloning such repository.

Related