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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:22:52+00:00 2026-05-29T22:22:52+00:00

Sometimes, I create local branches in git, and I’d like to get a warning

  • 0

Sometimes, I create local branches in git, and I’d like to get a warning message when I try to dcommit from them.

How can I prevent myself from accidentally dcommiting from a local branch?

  • 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-29T22:22:53+00:00Added an answer on May 29, 2026 at 10:22 pm

    An alternative to pre-commit hooks, if you’re using Linux (or Git bash or Cygwin or similar), is to wrap git in a shell helper function. Add the below to your ~/.bashrc (for bash, Git bash) or ~/.zshrc (for zsh) file, or whatever the equivalent is for your shell:

    real_git=$(which git)
    function git {
        if [[ ($1 == svn) && ($2 == dcommit) ]]
        then
            curr_branch=$($real_git branch | sed -n 's/\* //p')
            if [[ ($curr_branch != master) && ($curr_branch != '(no branch)') ]]
            then
                echo "Committing from $curr_branch; are you sure? [y/N]"
                read resp
                if [[ ($resp != y) && ($resp != Y) ]]
                then
                    return 2
                fi
            fi
        fi
        $real_git "$@"
    }
    

    (I’ve tested this with bash and zsh on Red Hat, and bash on Cygwin)

    Whenever you call git, you’ll now be calling this function rather than the normal binary. The function will run git normally, unless you’re calling git svn dcommit while attached to a branch that’s not master. In that case, it’ll prompt you to confirm before doing the commit. You can override the function by specifying the path to git explicitly (that’s what the $real_git is doing).

    Remember that after updating ~/.bashrc or equivalent, you’ll need to reload it, either by starting a new shell session (logging out and logging in again) or by running source ~/.bashrc.

    Edit: As an enhancement, you can remove the first line, starting real_git=, and replace the other instances of $real_git with command git, which achieves the same thing but in the preferred way. I’ve not updated the script itself as I’ve not been able to test the change on zsh.

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

Sidebar

Related Questions

When you code in other languages, you will sometimes create a block scope, like
In my application, I sometimes have to create elements dynamically, so I create them
I'm working with LINQ in VB.NET and sometimes I get to a query like
Sometimes I create some quick personal projects using C# with Windows Forms or WPF
Sometimes you need to create a very simple single file application in Qt4. However
Sometimes in Salesforce tests you need to create User objects to run part of
I see Oracle procedures sometimes written with AS, and sometimes with IS keyword. CREATE
As a C++ programmer I sometimes need deal with memory buffers using techniques from
Sometimes we like to take a large parameter by reference, and also to make
I have a local git repository created with git svn clone . I make

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.