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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:10:50+00:00 2026-05-28T20:10:50+00:00

I want to setup git for a somewhat unusual use case. I have a

  • 0

I want to setup git for a somewhat unusual use case.

I have a repository server (‘repo’) and I have a develop server (‘develop’) I want to deploy to. On the repo server I have a bare repo (‘origin’) which I push my changes to from my local clone.

When I push a branch called ‘development’ to the repo server, I have a post-receive hook there that pushes the branch to the development server:

#!/bin/bash

# post-receive on repo server

while read oldrev newrev ref
  do
  branch=`echo $ref | cut -d/ -f3`

  if [ "development" == "$branch" ]; then
    git push develop development
    echo 'Changes pushed to development server.'
  fi
done

exit 0;

On the development server I have a post-receive hook that reads

#!/bin/bash
GIT_WORK_TREE=/srv/www/htdocs/develop git checkout -f

On the develop server it might be the case that someone made changes directly in the the working tree which resides in /srv/www/htdocs/develop without using git (yeah, I know, don’t ask…).

Now: What is the best way to prevent the checkout on the develop server which would destroy the non-gitters modifications?

At the moment I simulate this case using a pre-receive hook on the repo server which echoes a message and exits 1.

It would be great if I do

$ git push origin development

and git would answer like so:

Counting objects: 11, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 706 bytes, done.
Total 9 (delta 3), reused 0 (delta 0)
remote: Unclean working directory on development server. Please fix that first.
To git@repo:development
 ! [remote rejected] development -> development (pre-receive hook declined)
error: failed to push some refs to git@repo:development'
  • 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-05-28T20:10:52+00:00Added an answer on May 28, 2026 at 8:10 pm

    I am using the “offical” post-update hook mentioned here: https://stackoverflow.com/a/3838796/3408
    to prevent update the remote checkout after push.

    I took some code from that to initialise the environment, and made a script to run git diff --exit-code --stat in a pre-receive hook. The --exit-code means that if there are differences, the push will be refused.

    #!/bin/bash
    
    is_bare=$(git config --get --bool core.bare)
    
    if [ -z "$is_bare" ]
    then
        # for compatibility's sake, guess
        git_dir_full=$(cd $GIT_DIR; pwd)
        case $git_dir_full in */.git) is_bare=false;; *) is_bare=true;; esac
    fi
    
    if [ "$is_bare" = "false" ]
    then
        active_branch=`git symbolic-ref HEAD`
        export GIT_DIR=$(cd $GIT_DIR; pwd)
        GIT_WORK_TREE=${GIT_WORK_TREE-..}
        while read oldrev newrev ref
        do
            if [ "$ref" = "$active_branch" ]
            then
                (cd $GIT_WORK_TREE; git diff --exit-code --stat >&2)
            fi
        done
    fi
    

    I’ve just got this working, it’s only basically tested. Others may be able to comment on if this can be simplified or improved.

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

Sidebar

Related Questions

We have recently migrated to Git from SVN. We have setup a bare repository
I have a GIT repository on bitbucket, which I want my Jenkins Server to
I have a remote git repository setup for centralized development within my team. However,
I want to setup a simple site and I don't have any web development
I have a folder, which I use git init, then, I use git add
I want to build up a git server which provider source management on the
I currently have a git setup where git is a user on my linux
We have a problem/misunderstanding with our current git setup. We have local master and
My friend and I have elected to use git and GitHub to collaborate on
I have a repo setup, and am just learning about how branches work. Right

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.