Click here to Skip to main content
14,302,135 members
Rate this:
Please Sign up or sign in to vote.
See more:
I know this kind-of goes against the whole ethos of Git but ...

Is it possible in Visual Studio to get some kind of warning before editing a file for the first time on a particular branch?

I'd like to adopt the good practice of always creating a new branch before I begin work on new code but - try as I might - I always start my code editing and then after editing one or more files realise that I am working on the main develop branch.

What I'd like is some way to semi-protect a branch so it pops up a warning or is read-only (or gives me a mild electric shock) so I am forced to create a new branch for each feature.

In defence of my this-is-just-not-the-Git-way question, I spent years working with Microsoft SourceSafe. It works completely differently and I wouldn't want to go back to it but I did like the fact that checked-in files could be read-only, so I knew when I was starting something new.

I should point out that this is for use on a local Git installation that pushes to a remote BitBucket account.

Any suggestions would be appreciated.

What I have tried:

I've tried a good Google session and looked at various Visual Studio Extensions.
Updated 31-Oct-18 5:39am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I do not know about this rule but you should check out the Settings section in your GitHub project - there are actually settings that can be used to guard against commiting to the master branch.

There are branch protection rules that you can use to guard individual branches:
Defining the mergeability of pull requests - User Documentation[^]

You can create a branch when you commit your code. Just make sure you are on the correct branch when you commit

-> when you do that you should realize that you are on the master branch - you can still create a local branch before commiting it - then when you publish - you will publish to a branch instead of master.
Patrick Skelton 31-Oct-18 11:37am
Thanks for the answer. Unfortunately that will not work for me as I am not using GitHub. I am using a local Git installation and pushing to a remote BitBucket account.

Sorry, I should have been clearer. I will modify my original question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100