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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:25:02+00:00 2026-05-24T23:25:02+00:00

I have several non-bare Git repositories. There is one central Git repository (or at

  • 0

I have several non-bare Git repositories. There is one central Git repository (or at least handled as being the central repo; this might change) but this is also non-bare (because I want to have a checkout on the same machine). My history is mostly linear and I’m the only person who will ever do changes on this repository, so it is unlikely that conflicts will happen. (It is my documents directory.)

Pushing directly into another non-bare repository doesn’t work if I use the master branch everywhere. There is receive.denyCurrentBranch which would allow this but it doesn’t really help me because (1) it doesn’t update the local checkout and (2) I’m afraid of what happens in case there is a conflict.

There are a few related/similar questions here:

  • simplest way to sync a repository with a checked out branch: Suggests setting up an Bash alias (basically ssh git pull).
  • making pushes to non-bare repositories safe: Using a post-update hook (with a strong advise to avoid it). Or rather push it to some specific unique remote ref and let the destination later handle the merging.

I want a solution which is 100% safe. So I think using a post-update hook is no option for me.

I think my use case is not actual that uncommon so I wonder if there are some common solutions for this. Are there?

I think, what I want is:

  • Push local master to some remote special ref (like merge-request-xy) (i.e. like git push origin master:merge-request ?).
  • On the remote, if we can fast-forward and the working copy is clean, fast-forward, update the working copy and delete the ref (basically git merge merge-request && git branch -D merge-request ?).

Would that be safe or a good way to do it?

  • 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-24T23:25:03+00:00Added an answer on May 24, 2026 at 11:25 pm

    The solution you have suggested is safe as long as you (1) push to a different branch than master, like merge-request and (2) do the checks about merging. For the second part, fast-forwarding if everything is in the clear on the remote, you can use a post-update hook like this one:

    #!/bin/sh
    
    # check args to see if merge-request was pushed,
    # and do nothing if it wasn't
    if ! $(echo $@ | grep -q 'merge-request');
    then
     echo "merge-request not updated"
     exit 0
    fi
    
    # cancel if master is not checked out
    THIS_BRANCH=$(git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
    if [ "$THIS_BRANCH" != "master" ];
    then
      echo "master not checked out, not merging"
      exit 1
    fi
    
    # cancel if working dir is dirty
    if [ $(git status --porcelain | wc -l) != 0 ];
    then
      echo "working dir is dirty, not merging"
      exit 1
    fi
    
    # try to merge, but only do so if the merge is fast-forward
    # try to delete, but only do so if the merge succeeded
    git merge --ff-only merge-request && git branch -d merge-request
    

    Make sure to chmod +x your post-update script. When you push, output of this hook will be shown in the console prefaced by “remote:”

    In order to push from master into origin/merge-request on the remote, you can either set the push var in your remote config in .git/config (which lets you call git push origin:

    [remote "origin"]
        push = +refs/heads/*:refs/merge-request/*
    

    or you can set a repo-specific alias:

    [alias]
        push = push origin master:merge-request
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with several non PK-related indexes. Unfortunately there's some duplicity in
I have several hundred files in a non-flat directory structure. My Makefile lists each
I have several questions on the following sequence of events. There are 2 developers
I have a non-static class in which i have several properties, ie serverURL, serverPort
I have several .asm files with non-inline assembly, and if I include them in
I have several Installshield 12 setups (using non-msi Installscript based setups) for several different
I have several sortable lists connected together, so I can drag one item from
I have several non-consumable inApps. The payment is done once (correctly: SKPaymentTransactionStatePurchased), then the
I have a user control on a form that can spawn several non-modal child
I have a single controller, Index , that manages several non-specialized informational pages (e.g

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.