Check response of git push from shell script

I’m trying to detect from bash if my git push was successful. I am checking for local changes previously in my script like this:

if [ -z "$(git status --porcelain)" ]; then

and that works fine. This is the expression I have tried but this one doesn’t work, in fact it errors:

  • -bash: hooks/post-receive: Permission denied
  • Check if branch exists in git repo without making a clone
  • Git clone into current directory of a new PC with same files locally than on remote repository
  • Middleman asks if I want to use compass when starting a new project
  • Automating git commit message per branch
  • Add date to git commit message automatically
  • if [ "$(git push --porcelain)" -eq "Done" ]; then


    Done: integer expression expected

    When I run git push --porcelain from the command line, the output is Done. Does this mean I should be checking for that text in my condition?

    If I do the previous comparison, that doesn’t work either, I get the same error:

    1 file changed, 309 insertions(+)
    Current branch master is up to date.
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 3.59 KiB | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    bash: [: To
            refs/heads/master:refs/heads/master     88aff43..cf0c97c
    Done: integer expression expected

  • Pull all branches from origin
  • Installing git through .ebextensions on Elastic Beanstalk
  • What does the “@@…@@” meta line with at signs in svn diff or git diff mean?
  • EGit 2.3 new --no-ff option, how to use it?
  • Apply git diff/patch multiple times
  • how can I create an archive before git svn dcommit?
  • 2 Solutions collect form web for “Check response of git push from shell script”

    Your condition check should have been something like:-

    if [[ "$(git push --porcelain)" == *"Done"* ]]
      echo "git push was successful!"

    -eq is for integer comparisons, == is for string comparisons. The following illustrates the difference.

    [[ 00 -eq 0 ]] && echo "zero is zero, regardless of its representation"
    [[ 00 = 0 ]] || echo "00 and 0 are two different strings"

    git push returns a zero exit code on success, and non-zero on failure.

    So you can write:

    if git push
      echo "git push succeeded"
      echo "git push failed"
    Git Baby is a git and github fan, let's start git clone.