Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab rename branch and start over on another

I just started on a new project and I'm using GitLab with SourceTree. I had created a branch (origin\master) but I did the mistake of using this branch for my development, so I pushed my first few changes to this branch. Now I learned that this branch should actually have the production version and that an origin\develop branch should be used for development.

Is there any way I can rename the master branch to origin\develop and somehow create a new origin\master branch with the original version of the application?

I'm the only developer in the project so it won't affect anyone. If possible, if you can explain how to do it in SourceTree since I don't use the command line git. I'm more familiar with SourceTree.

like image 815
Ray Avatar asked Jan 31 '16 20:01

Ray


People also ask

Can I rename branch name in GitLab?

The steps to change a git branch name are: Rename the Git branch locally with the git branch -m new-branch-name command. Push the new branch to your GitHub or GitLab repo. Delete the branch with the old name from your remote repo.

Can you rename an existing branch in git?

You created a new branch , pushed the changes to the remote repository, and realized that your branch name was incorrect. Luckily, Git allows you to rename the branch very easily using the git branch -m command.


1 Answers

You could try something like this. Answer modified from this great answer, to suit OP's needs.

git branch -m master develop    # rename master on local git push origin :master         # delete master on remote git push origin develop         # create develop on remote git checkout -b master develop  # create a new local master on top of develop git push origin master          # create master on remote 
like image 133
DominicEU Avatar answered Sep 20 '22 15:09

DominicEU