Skip to content

Instantly share code, notes, and snippets.

@sunsided
Last active February 19, 2024 20:57
Show Gist options
  • Save sunsided/94dd71b15d6ea994f8523f1af8e049ae to your computer and use it in GitHub Desktop.
Save sunsided/94dd71b15d6ea994f8523f1af8e049ae to your computer and use it in GitHub Desktop.
Git tricks to merge orphan branches
# 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