If your script allows for non-zero exit codes, then:
#!/bin/bash
file_path=gs://main-bucket/sub-directory-bucket/object1.gz
gsutil -q stat $file_path
status=$?
if [[ $status == 0 ]]; then
echo "File exists"
else
echo "File does not exist"
fi
But if your script is set to fail on error, then you can't use exit codes. Here is an alternative solution:
#!/bin/bash
trap 'exit' ERR
file_path=gs://main-bucket/sub-directory-bucket/object1.gz
result=$(gsutil -q stat $file_path || echo 1)
if [[ $result != 1 ]]; then
echo "File exists"
else
echo "File does not exist"
fi