Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons for not working on the master branch in Git

So, I'm fairly new to git and I've after a bit of reading around over the last couple of weeks I've read a few people saying that the master branch shouldn't be changed but rather branched from and then merged to.

I'm happy enough to work with branches but was wondering for the reasons behind not working on the master branch?

like image 828
Mark Williams Avatar asked Apr 19 '11 08:04

Mark Williams


People also ask

Why is it a bad practice to work directly on the master branch in git?

Working directly in master means that if you create bugs you have no other option for "going back" than to reverse/delete/reset commits, which is not a clean way of working and can cause you to lose the parts of the new code that were OK.

Should you work on master branch git?

Work should never be done in this branch. Instead of working in master, changes should be merged in via Pull Requests from other feature branches or from a fork. To this end, you should protect the master branch to encourage code reviews before changes are merged and deployed.

How do I activate the master branch?

In order to switch to the master branch, on this specific commit, we are going to execute the “git checkout” command and specify the “master” branch as well as the commit SHA. In order to check that you are correctly on a specific commit, you can use the “git log” command again.


1 Answers

Other people have made very good cases for not making changes directly in master, and I agree with them. However, always advocating workflows like this sometimes leads people new to git to believe it is needlessly complex, so I wanted to provide a counterpoint.

If you have a one-person or very small team and your development is highly linear, i.e. you rarely work on more than one thing at a time and each feature is usually completed before starting the next, there really is little to no benefit to not work directly out of master. It is very easy to go back and add a branch at any point should the need arise. I highly recommend being aware of the feature branch workflow, but if you feel in your case it's just adding extra steps without buying you anything, I promise I won't tell the git police.

like image 110
Karl Bielefeldt Avatar answered Oct 15 '22 03:10

Karl Bielefeldt