GitLab rename branch and start over on another

103,180

Solution 1

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

Solution 2

SourceTree instuctions as of version 2.0.20.1

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

Solution 3

You could try something like this.

git branch -m <old_branch_name> <new_branch_name>
Share:
103,180
Ray
Author by

Ray

I'm a Montreal-based software developer with a strong background in Windows development, database development, and web development. I currently specialize in Microsoft's .NET, C#, and MVC technologies with a multitude of successful projects under my belt. After completing my university degree in Computer Science, I began as a computer consultant helping many businesses around Montreal reach their I.T. goals. Now after 20 years of experience, I enjoy developing with the latest web technologies, and constantly learning the newer ones as they come along.

Updated on November 03, 2021

Comments

  • Ray
    Ray over 2 years

    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.

  • David Deutsch
    David Deutsch about 8 years
    Shouldn't git checkout -b master develop be git checkout -b master <commit>, where <commit> is the last commit that was originally on master?
  • DominicEU
    DominicEU about 8 years
    Yes, that would work great if OP knows those details!
  • Jochem Schulenklopper
    Jochem Schulenklopper over 6 years
    Compliments for actually addressing SourceTree, as requested in the original question.
  • Randall
    Randall over 5 years
    I didn't know I could delete a branch on the remote like that - nice! I just wanted to rename a development branch that I'd already pushed up, and using the first 3 steps (with my devel branch names) worked beautifully!
  • Motti Shneor
    Motti Shneor over 5 years
    the OP clearly said his "master" should reflect the "original version of the application" which means he knows what commit it is - or maybe even it is the first commit in his repository. So I think you should enhance your answer (which is otherwise great!) to not recreate master on top of "develop" - but on top of another commit or branch.
  • derHugo
    derHugo about 4 years
    quite risky though .. if anything goes south your progress is lost. I would rather: 1. Locally create a new branch from the existing one (simply click on Branch in the top menu bar) -> give it the desired name, push the new branch to remote, after upload delete the old branch local and on remote(s)