0

I have a project branch and a master branch in my Git project. I would like to make the project branch become the master branch. However, I would like to keep the old master branch as a side branch. How can I do this?

Current:

----------- master
    \______ project

What I want:

-------------------- project (new master branch)
    \______ master (old)
frozen
  • 2,114
  • 14
  • 33

3 Answers3

1

If you want to exchange the name of the branches, probably the easiest way would be:

git checkout --detach master # we put HEAD on master
git branch -f master project # move master to project (HEAD doesn't move)
git branch -f project # set project to HEAD
git checkout project
eftshift0
  • 26,375
  • 3
  • 36
  • 60
0
// If you want to still retain the old master branch, then create a tag or new branch on that particular commit so you don't loose it:

git checkout master

git checkout -b master-old

// now if you want to go back to the old master branch you can checkout the master-old branch. 

// from here you can simply reset the master branch to the project branch

git checkout master

git reset --hard project

git checkout master

// now your master branch and the project branch should be pointing to the same commit. you can continue developing on your master branch. you may even want to delete the project branch. up to you.

EDIT: Don't do this if it's a public repo!!

BenKoshy
  • 33,477
  • 14
  • 111
  • 80
0

You just need to exchanges the branch names for the two branches by below way:

git branch -m master project1   #change master branch name as project1
git branch -m project master    #change project branch name as master
git branch -m project1 project  #change project1 branch name as project

Now your branch structure will looks like:

-------------------- project (new master branch)
    \______ master (old)
Marina Liu
  • 36,876
  • 5
  • 61
  • 74