3

Is there a way to check if a dir exists on a remote branch? I want to take the output and use it in a bash script to do some automations.
For now I found: How do I check if a file exists in a remote? but is not helping me.

The only useful command that I found and list the directories from the remote branch is this:
git ls-tree origin/master:<remote_dir>/<remote_subdir> and if the remote dir exists it will list all the files in that dir otherwise it will trow an error.

Are there other easy and cleaner solutions to do this? (without subdir listing for the remote dir)

Community
  • 1
  • 1
Starlays
  • 1,039
  • 2
  • 15
  • 29

1 Answers1

2

The documentation mentions the -d switch:

-d Show only the named tree entry itself, not its children.

So this should work:

git ls-tree -d origin/master:<remote_dir><remote_subdir>
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56