Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 22-Nov-19 0:41am
v3

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.
 
Share this answer
 
v2
Comments
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.
I've come up with a partial solution to this. I have a small batch file that I run from a Visual Studio keyboard shortcut that makes every source file in my local copy of the project read-only.

I can usually remember to run this whenever I complete a feature on a branch in Git. So when I next come to start a new feature and I try to edit a file, I get a warning saying the file is read-only. (It reminds me of my not-so-good old days of using Microsoft SourceSafe.)

I guess most people would find the read-only warning annoying, but it is easily dismissed, and it does remind me to double-check that I have started a new Git branch whenever I start to work on anything new.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900