Search code examples
gitgithubgit-mergegithookscherry-pick

Git auto merge commits from another repo


I have 2 private repository (not branches) A and B of which I have full access to.

Whenever A makes a commit, I want B to cherry-pick or merge the new commit into it (assuming no merge conflicts), so that B will always be up-to-date with the latest changes from A.

How do I accomplish this with Git hook or something else?

A shell script is less flexible as it means you have to commit/push with command line rather than GUI (eg. with SourceTree).


Solution

  • In repository A create a post-commit hook that switches to repo B and runs git pull.

    The kind of "switching" depends on where B resides. If it's on the same computer the hook can just cd /path/to/B, but don't forget to clear GIT_DIR and GIT_WORK_TREE env vars before running git pull. If B is on another server the hook should ssh there.