How does shell capture git checkout command failure scenarios?

< H2 > problem description < / H2 >
while writing a shell script, I need to git checkout to a branch after cd to a directory.
however, in some cases, git checkout fails because the artificial modification file is not submitted.
< H2 > excuse me < / H2 >

should I judge that the execution of git checkout failed?

< H2 > current idea, but it seems to have no effect < / H2 >
if (cd abc/ && git checkout master); then
    echo "ok"
else
    echo "fail"
fi
Mar.17,2021

cd abc && git checkout master

if [ $? -eq 0 ]; then
  echo "ok"
else
  echo "fail"
fi

has a more stupid way. Get his output information.. If the statement is not a successful switch, it is considered a switching error.

Menu