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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:08:14+00:00 2026-06-18T02:08:14+00:00

I have to configure read-only access for some remote branches of a controlled git

  • 0

I have to configure read-only access for some remote branches of a controlled git repository.

The scenario is as follows:

For our development, we have an internal “development repository” (1) that mirrors an “external repository”. This “development repository” gets periodic updates (git remote update in a cron job). Our development takes place in branches “dev_*” derived from the external repositories, but never direct on the external branch:

Repositories schema

The workflow for adding functionality to master:

  1. We create a branch dev_master with master as parent.
  2. John clones the repository development, checks out dev_master, works on it, and pushes regularly back to development.
  3. If the repository external gets master updated, so is master in development (due to the above mentioned cronjob), and someone can merge master on dev_master, so we keep in sync with external.

We need to forbid John’s pushes to the branch master of development, so his changes doesn’t get lost after the periodic update from external.

Again, schematic:

Repositories summary


Notes

(1) I could find that some people call this development repository “staging repository” (for example, in How do I setup a staging repository in git?, where a very similar situation has been presented)

  • 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-18T02:08:15+00:00Added an answer on June 18, 2026 at 2:08 am

    I forbid these pushes using a Server-Side hook. From git help hooks:

    pre-receive
    This hook is invoked by git-receive-pack on the remote repository, which happens when
    a git push is done on a local repository. Just before starting to update refs on the
    remote repository, the pre-receive hook is invoked. Its exit status determines the
    success or failure of the update.
    […]
    If the hook exits with non-zero status, none of the refs will be updated. If the hook
    exits with zero, updating of individual refs can still be prevented by the update
    hook.
    […]

    The hook code:

    #!/bin/bash
    
    # Read the branches of the remote repository
    remote_branches=$(git ls-remote --heads | sed "s,.*\(refs/heads/\),\1,")
    
    function forbid_push_to_remote_branches()
    {
        while read old_value new_value ref_name
        do
            # Test for existence of [$ref_name] in remote
            for remote_branch in $remote_branches
            do
                if [[ $remote_branch == $ref_name ]]
                then
                    invalid_refs="$invalid_refs [$remote_branch]"
                    break
                fi
            done
        done
    
        # if remote read-only branches found, exit with non-zero
        # and list these branches
        if [[ -n $invalid_refs ]]
        then
            echo "ERROR: You are trying to push to remote branch(es):" >&2
            echo "   $invalid_refs" >&2
            return 1 
        else
            return 0
        fi
    }
    
    forbid_push_to_remote_branches
    exit $?
    

    This code must be copied to the file $(bare_repo_path.git)/hooks/pre-receive in the server (there is no pre-receive.sample).

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

Sidebar

Related Questions

Is is possible ot configure Chainsaw to read log files that have been customized
I have tried to configure alternate access mappings in my SharePoint 2010 which is
I have an R package on github that uses a configure script (since some
I'm trying to configure my local development environment to read .less files so that
I have used emacs for erlang programming. According to http://emacswiki.org/emacs/CompileCommand , I have configure
I am using asp.net .. i have created one small application.. I have Configure
I'm currently setting up CI for my project and have team city configure and
I have a problem to configure the Kendo-Ui with Combo-box with custom values. I
I have a windows application (C#) and i need to configure it to run
I have created a UItableView using the default Xcode template and configure it to

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.