Skip to content

Instantly share code, notes, and snippets.

@larrybotha
Last active October 21, 2024 15:28
Show Gist options
  • Save larrybotha/10650410 to your computer and use it in GitHub Desktop.
Save larrybotha/10650410 to your computer and use it in GitHub Desktop.
Merge wiki updates that are on a fork of your repo.

Merge Wiki Changes From A Forked Github Repo

This is inspired (or basically copied) from How To Merge Github Wiki Changes From One Repository To Another, by Roman Ivanov, and serves to ensure that should something happen to the original article, the information remains nice and safe here.

Terminology

OREPO: original repo - the repo created or maintained by the owner

FREPO: the forked repo that presumably has updates to its wiki, not yet on the OREPO

Contributing

Should you want to contribute to the wiki of a repo you have forked, do the following:

  • fork the repo
  • clone only the wiki to your machine: $ g clone [FREPO].wiki.git
  • make changes to your local forked wiki repo
  • push your changes to GitHub

Once you are ready to let the author know you have changes, do the following:

  • open an issue on OREPO
  • provide a direct link to your wiki's git repo for ease of merging: i.e. [FREPO].wiki.git

Merging Changes

As the owner of OREPO, you have now received a message that there are updates to your wiki on someone else's FREPO.

If wiki changes are forked from latest OREPO wiki, you may do the following:

$ git clone [OREPO].wiki.git
$ cd [OREPO].wiki.git

# squashing all FREPO changes
$ git pull [FREPO].wiki.git master

$ git push origin master

If OREPO wiki is ahead of where FREPO forked from, do the following:

$ git clone [OREPO].wiki.git
$ cd [OREPO].wiki.git
$ git fetch [FREPO] master:[FREPO-branch]
$ git checkout [FREPO-branch]

#checkout to last OREPO commit
$ git reset --hard [last-OREPO-commit-hash]

# do massive squash of all FREPO changes
$ git merge --squash HEAD@{1}
$ git commit -m "Wiki update from FREPO - [description]"
$ git checkout master

# cherry-pick newly squashed commit
$ git cherry-pick [OREPO-newly-squashed-commit]
$ git push
@faahim
Copy link

faahim commented Feb 20, 2018

Amazing! I didn't even know wiki act as a different git! Thanks for sharing! 😄

@bitaxis
Copy link

bitaxis commented Apr 18, 2018

This gist worked for me. Thanks a lot! 👍

@jmace01
Copy link

jmace01 commented Jun 14, 2019

@sketch34, you have to create a page on your forked wiki (via the GitHub website) to create/initialize the wiki repository. Before that, it can't be accessed.

@giovp
Copy link

giovp commented Nov 5, 2019

@sketch34 same problem here, this solved it: https://stackoverflow.com/a/56480628

@pa-0
Copy link

pa-0 commented Oct 17, 2024

FYI, you can also enable the wiki using the GitHub API (using the GitHub CLI or cURL):

curl -L \
  -X PATCH \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO \
  -d '{"name":"Hello-World","description":"This is your first repository","homepage":"https://github.com","private":true,"has_issues":true,"has_projects":true,"has_wiki":true}'
## <"has_wiki":true> to enable and <"has_wiki":false> to disable a wiki for a repository you own

More info here: GitHub API Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment