0

I'm starting to learn Git. I use Bitbucket and I created a master branch. But I would like to have a dev branch instead and then push the code to the master branch when it is production ready.

How would I do that now that I just created the master branch? Can I change the name of the branch and create a master branch later?

Braiam
  • 1
  • 11
  • 47
  • 78
Daoro
  • 23
  • 4
  • Possible duplicate of [How to rename a local Git branch?](http://stackoverflow.com/questions/6591213/how-to-rename-a-local-git-branch) – TerraPass Jul 25 '16 at 21:53
  • Possible duplicate of [Push a new local branch to a remote Git repository and track it too](http://stackoverflow.com/questions/2765421/push-a-new-local-branch-to-a-remote-git-repository-and-track-it-too) – Jeeter Jul 25 '16 at 22:01

2 Answers2

1

Think a little bit long term. You want to use master branch at release points, which is an acceptable approach. You need to copy the content of dev into master when that point is reached. Renaming might seem as a viable way to do this at that point, but it is not. Git is all about keeping the history and separate flows of code. Think what you will do after the rename operation. Renaming dev to master simply creates a master which contains each step of development and destroys dev. If that's your goal you can simply do all the development on master which I believe is not what you want.

You can use master as a summary of your project. Then dev includes all gorry details. When you are ready to release you merge from dev to master (possibly with a pull request). That way master takes all your work as a single commit.

You can see an example branching strategy that is based you a slightly more complicated version of your idea here. In this strategy master is also used only for releases. A develop branch is where you have all the major development. Moreover feature branches, hotfix branches and release preperation branches are used. The document also shows ways to achieve all merges in pure Git, but when you get the idea you can implement it on Bitbucket more easily.

infiniteRefactor
  • 1,940
  • 15
  • 22
0

Your master branch is supposed to be the set-in-stone (of sorts) copy of your repository. That means that you should have a master branch at all times.

What I would suggest is simply creating a new branch:

git checkout -b dev

and then create pull requests to the master branch as you update it

Graham
  • 7,431
  • 18
  • 59
  • 84
Jeeter
  • 5,887
  • 6
  • 44
  • 67