Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8427557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:48:45+00:00 2026-06-10T04:48:45+00:00

I am writing a post-update script for a git repository and am having a

  • 0

I am writing a post-update script for a git repository and am having a bit of trouble.

For whatever reason the if statement is throwing an error:

hooks/post-update: line 5: [master: command not found

I simply want to check and see if the pushed branch is equal to “master”. I am guessing there is something wrong with my syntax, this is my first sh script, but I’ve tried several variations with no luck.

Thanks for any help,

#!/bin/sh

BRANCH=$(git rev-parse --symbolic --abbrev-ref $1)

if ["$BRANCH" = "master"]
then
    cd $HOME/domain.com || exit
else
    cd $HOME/dev.domain.com || exit
fi

unset GIT_DIR
git pull hub $BRANCH
git checkout $BRANCH
exec git-update-server-info
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:48:47+00:00Added an answer on June 10, 2026 at 4:48 am

    The square brackets must be separate tokens! You see, it tries to look like nice syntax, but the fact is, that there is a (built-in in most shells) command [. So the syntax should be:

    if [ "$BRANCH" = "master" ]
        ^                    ^
        +--------------------+-- There have to be spaces here!
    

    Without the first space the command becomes [master and such command does not exist — the command is [. Without the second space, the right argument will be master] and won’t match (and than [ will fail with “missing ] argument” error.


    Detailed description:

    The shell if syntax tries to be as simple as possible. It really is

    if command than command [else command] fi

    where each command has to be terminated either by semicolon or end of line. So you can write things like

    if grep -q foo somewhere
    then
        whatever
    fi
    

    Now in many cases you need to do things like compare strings, compare numbers, test whether file exists, test whether one file is newer than another etc. For this there is a standard command test (which is built-in in most shells, but external version always exists). It allows things like

    test "$foo" == "bar"
    test -n "$this_variable_must_be_nonempty"
    test -f "$this_file_should_exist"
    

    This is what you use in if. For sake of nicer syntax, this command has alias [ which accepts exactly the same arguments, except it requires ] as it’s last argument so the condition looks pretty. This is also built-in in most shells, but usually exists as symlink to test too. So don’t be fooled by what looks like special syntax; it is simple program invocation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there any way to enable echo in git hook /var/git/repositories/project.git/hooks/post-update #!/bin/bash unset GIT_DIR;
Im writing a php script that is used to update a database but it
I am currently writing an Edit Account module. Using jQuery.post(); I can successfully update
Ok, So I'm writing a task organizer script and I'm having some issues with
Im writing a form to post data off to paypal, and this works fine,
I'm writing a simple function that split binary/post-data/html from a HTTP response. The HTTP
I am writing a Facebook application that needs to post on a friend's wall
Writing a python program, and I came up with this error while using the
I'm writing a PHP application which uses AJAX to submit forms via POST when
As I was writing my initial question I saw this post . I deployed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.