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 8200059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:18:19+00:00 2026-06-07T06:18:19+00:00

I have a remote server on which I have created a bare git repository.

  • 0

I have a remote server on which I have created a bare git repository.

I would like to create a hook so that a given script is run on the latest code received on any given branch.

I know the post-receive hook can be used for it. However I want to do the following:

  1. Get hold of the branch on which code was received.
  2. Checkout the code in a temp location and run an operation on it.

How do I do the above?

  • 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-07T06:18:21+00:00Added an answer on June 7, 2026 at 6:18 am
    • For 1), you have an example of reading the branch name (through stdin):
      “Not able to detect branch from Git post-receive hook“
    • For 2), you need to set GIT_WORK_TREE appropriately:
      “Managing website using git + post-receive hook: error pushing changes“

    See both techniques combined in “Git post-receive for multiple remote branches and work-trees“:

    #!/bin/bash
    
    while read oldrev newrev ref
    do
      branch=`echo $ref | cut -d/ -f3`
    
      if [ "master" == "$branch" ]; then
        git --work-tree=/path/under/root/dir/live-site/ checkout -f $branch
        echo 'Changes pushed live.'
      fi
    
      if [ "dev" == "$branch" ]; then
        git --work-tree=/path/under/root/dir/dev-site/ checkout -f $branch
        echo 'Changes pushed to dev.'
      fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an enterprise-like application that fetches data from a remote server. I have
I have a GIT repository on bitbucket, which I want my Jenkins Server to
I have a remote actor (client) which is registering with another remote actor (server)
I have an activity which needs to make two remote server calls. The first
We have a java application which run as server running on a remote windows
I have a remote server that has win2003 installed I can connect to the
I have a folder on my remote server that has a few .png files
I have deployed my app in remote server with capistrano and git. I'm novice
I have a large collection of my personal scripts that I would like to
I have an app that connects to a remote chat server and then the

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.