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 (originmaster) 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 origindevelop branch should be used for development.

Is there any way I can rename the master branch to origindevelop and somehow create a new originmaster 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.


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

SourceTree instuctions as of version 2.0.20.1

  • Rename Local branch under "BRANCHES"
  • Right click branch and select "Rename Name of your branch"
  • Delete remote branch under "REMOTES"
  • Right click branch and select "Delete origin/Name of your branch"
  • Push your renamed local branch to GitLab
  • Left click you renamed local branch
  • Click the "Push" button on the to ribbon bar

  • Easiest way to fix this is to revert the commit. If this was the last commit made, you can fix this by doing the following:

    $ git revert HEAD

    How to do this in source tree is below:

    http://flummox-engineering.blogspot.com/2014/10/how-to-undo-git-commit-in-sourcetree.html

    Now everything should be back to normal before the push you did to the wrong repository.

    链接地址: http://www.djcxy.com/p/94806.html

    上一篇: 为什么会用“git merge”

    下一篇: GitLab重命名分支并重新开始