Last active
February 19, 2024 20:57
-
-
Save sunsided/94dd71b15d6ea994f8523f1af8e049ae to your computer and use it in GitHub Desktop.
Git tricks to merge orphan branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Merge an orphan branch and overwrite our changes ("take theirs"). | |
git merge --allow-unrelated-histories -Xtheirs $ORPHAN_BRANCH | |
# List all files existing in branch "timeline" that do not exist in branch "$ORPHAN_BRANCH" | |
git diff-tree -r --diff-filter=D --name-only timeline $ORPHAN_BRANCH | |
# ... and delete them | |
git diff-tree -r --diff-filter=D --name-only timeline $ORPHAN_BRANCH | xargs -d '\n' git rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment