I have a Git repository which I have started to develop on master branch in and now I believe that master shouldn’t be a long running branch. As others, I think master branch always holds the stable product.
So, I would like to open a new branch named develop and that branch will be a long running development branch but I am not sure what would be the best approach to switch here. My current solution is this:
Open up the new branch and push it to GitHub:
git checkout -b develop
git push origin develop
Then get back to master branch and stop tracking all the files except for README.md and push it to remote repository (GitHub, in this case):
git checkout master
git rm . --cached -r
git add README.md
git commit -m "cleaned up the master branch"
git push origin master
What are your thoughts?
Your problem is with the NAME “master”.
A branch is a branch. None of them is really more important than any other. The name is literally just a tag–a string that identifies the current HEAD, and bumps along as that HEAD is committed on top of. But a branch’s “master”-ness is only important because that’s the name git gives the first branch it creates in a project. But that’s just a name. Let’s take your current master branch and give it a new name. Since what you call it is irrelevant, let’s choose “steve”.
Great. Now you HAVE no master branch! But you have the old steve branch that has historical work in it. That’s worth having around, but because you’re drawing a line in the sand in the history right now, you’ll likely never dip back into it.
So then check out your dev branch, work on it, etc. And when it’s stable (whatever that means in your particular case), create yourself a NEW master
Ha ha! First commit on that master branch is stable, and you can make sure all future commits are too! (BTW you’ll want –no-ff on all merges from devel into master, to keep those intermediate potentially nonstable commits out of your shiny new “master” branch.)