gitgithubgit-bash

How to create new orphan git branch and keep only one folder?


I tried this

git checkout --orphan newfeature/lk1

Inside I have

A,B,C....

my goal was delete all except the one,A

find . -name A -prune -o -print0 | xargs -0 rm

It did not work for me. I am using GitBash. What should I do?


Solution

  • Use a pathspec [1] to match on all except A/.

    git checkout --orphan branch
    git rm -r -f -- ':!A/'
    git commit
    

    Notes

    1. Accessed when the page was last updated in Git 2.51.0