Merging two pgn files is an operation, that makes just one game variation, and the one of the game gets added as a variation to the other game. If both the games have similar opening, then the similar opening moves are eliminated and a variation is created at the point when both the games starts to differ.

In Chessbase software (or any other chess tools), it is easy to merge normal chess games, we just copy the game and paste it into another, and it gets added as a variation. If if we have to do this for multiple games, it get laborious and manual process of merging. It will be good if some automated script exists for this purpose.

  • 1
    I know Im nitpicking but to me merging files is a different thing than merging the games from 2 pgn files into one game
    – Purefan
    Sep 21, 2023 at 12:29

2 Answers 2


A piece of code that works perfectly for merging pgns is.


The code is not regex heavy, thanks to python-chess library. It can merge several pgn games into a single pgn with one game including all moves as variations.

All headers and comments are ignored as this is designed only to manipulate the move lines.


I looked at the merge-pgn tool and made some modifications to it to have support for also merging text comments and also software comments/annotation (arrows and circles etc). There are some technical caveats but it works. The modified version is available here.

For those who can't be bothered to install Python, and who doesn't have Chessbase, chesstempo is another free tool that also does real PGN game merging, but there are some issues with that.

In order to get a clean merge, you have to remove all existing repertoires and reload the page before uploading the PGN files to merge, and then export them. If you are already using the opening trainer at chesstempo.com you would have to first export/backup your repertoires and then re-upload them afterwards which could be a nuisance. Also, while it does merge the text comments, it doesn't really merge the annotations (arrows and circles), and it will also include annotations from repertoires of the opposite color (hence the reason why you need to remove all repertoires before you begin). There is a discussion regarding these subtleties at the site's forum.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.