Search code examples
gitgit-show

How to get list of files in another branch without checkout


I want to list the files present in another branch without doing a checkout, and according to View a file in a different Git branch without changing branches, this command is sufficient:

git show mybranch:mydir

Unfortunately, the output is not ideal because of the completely unnecessary tree mybranch:mydir:

tree mybranch:mydir

.gitignore
Makefile
README

How can I list the files in another branch without getting any extra information (e.g. tree mybranch:mydir)?


Solution

  • That would then be

    git -p ls-tree -r --name-only mybranch:mydir
    

    Drop -p if you do not need the pager. Drop -r if you do not want to descend into directories recursively.