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

  • SEARCH
  • Home
  • 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 8145179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:35:05+00:00 2026-06-06T13:35:05+00:00

I have a Git repository in bitbucket and another on my live rails server,

  • 0

I have a Git repository in bitbucket and another on my live rails server, How can I make it so whenever i push to bitbucket it, the live server pull it from bitbucket as well?

I found this snippet online, and i put it on my live server’s git hooks as post-receive, but i don’t know what to do next:

#!/bin/sh
name=$1
if [ -z "$name" ] ; then
        echo "need to give name of checkout dir on command line"
        exit 1
fi

dir=/srv/web/$name
if [ ! -d $dir ] ; then
        echo "the directory $dir does not exist"
        exit 1
fi

cd $dir
env -i git pull
rake db:migrate
touch $dir/tmp/restart.txt

Can anyone point out what should i do to make this happen? I’ve seen post hooks on bitbucket (similar to github) but i’m not sure what to do.

  • 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-06T13:35:06+00:00Added an answer on June 6, 2026 at 1:35 pm

    Analysis

    BitBucket has a number of service hooks, but none of the ones I’ve
    used are explicitly for triggering deployment scripts. You could role
    your own using the BitBucket broker API, but this is generally not
    the right thing to do.

    The received wisdom is to use deployment scripts from continuous
    integration, so that you’re only deploying successful builds. Note that
    I said “deploying,” not “pushing,” because you can’t push to a
    repository with a working tree.

    However, it’s certainly possible to trigger a Rails update without
    continuous integration, post-receive hooks, or deployment tools such as
    Capistrano. Polling is one alternative.

    Solution

    While a post-receive or service hook can trigger an arbitrary action on
    commits, the simplest thing to do is just to poll Git from your web
    server. For example, you could run a cron job every minute to pull the
    current master branch into a working tree under your web root.

    First, install and test your polling script. I generally use a variation
    of this:

    #!/bin/bash
    # Script:
    #     git_poll.sh <appname>
    # Purpose:
    #     Poll your Rails repository for changes.
    
    set -e
    
    WEBROOT='/var/www'
    MY_RAILS_APPNAME="$1"
    shift
    
    # Use the flock(1) utility to guard against long-running fetch or merge
    # operations using the flock(2) system call. On Debian-based systems,
    # this tool is found in the util-linux package.
    (
        flock -n 9 
    
        cd "$WEBROOT/$MY_RAILS_APPNAME"
        git fetch origin master
    
        # Check if heads point to the same commit.
        if ! cmp --quiet <(git rev-parse master) <(git rev-parse origin/master)
        then
            git pull --force origin master
            touch "$WEBROOT/$MY_RAILS_APPNAME/tmp/restart.txt"
        fi
    ) 9> "/var/lock/polling4${MY_RAILS_APPNAME}"
    

    This script assumes you’re using Phusion Passenger. If you’re using
    something else, you may need to modify the script to take some other
    action after Git pulls from the remote repository.

    Next, make sure the script is executable. chmod 755
    /usr/local/bin/git_poll.sh
    should do it.

    Finally, update your Rails user or system crontab with something similar
    to the following:

    * * * * * /usr/local/bin/git_poll.sh example_app
    

    Since we’re using exclusive locking in the script, polling every minute
    should be fine. If you don’t use locking, or want to reduce load on your
    systems, then set a longer polling interval in your crontab.

    That’s it! Now when you push to origin from development or QA, your
    Rails server should update itself within a minute or so. That’s usually
    sufficient for most purposes, and hopefully yours as well.

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

Sidebar

Related Questions

I have a git repository on my server i can ssh over port 443.
I have a GIT repository on bitbucket, which I want my Jenkins Server to
I have git repository on bitbucket. I use it from Eclipse for a while,
I have bitbucket git repository. I tried to clone it from my PC, but
I have setup a git repository in a linux server, and installed the latest
I have a hosted git repository in my own server and my git repo
I have a git repository imported from subversion where users have names like H1234567
I have a Git repository that is accessed from both Windows and OS X,
I have a local git repository. Recently I have added a remote repository from
I have git repository (powered by gitosis) on my local ubuntu server I want

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.