Reputation: 147
I have been working on a project using git. I have two branches master and feature. With the time I added more commits to the feature branch. And the feature branch is 5 commits ahead of master.
Now, I want to make the feature branch 'master'. And the master branch to a normal branch. There is a way to replace master branch with another branch in here using ours merge strategy, but the commits of the previous master are lost because the feature branch overrides them.
Is there a way to switch the master branch and the feature branch without loosing the commits of both branches?
Upvotes: 3
Views: 119
Reputation: 38106
So you want to rename master
branch to a normal branch (such as Mybranch
) and rename feature
branch to master
. You can use below commands:
git branch -m master Mybranch
git branch -m feature master
To switch the remote branch based on the new branch name, you can use below commands:
#Change the remote master same as the new local master branch
git push -u origin master -f
#Push Mybranch to remote
git push -u origin Mybranch
#Delete remote feature branch
git push :feature
Upvotes: 1