简体   繁体   中英

How to make a git branch the new master?

A few days ago, I created a new git branch using:

git checkout -b release-1_5

Since creating that new branch, I've made additional changes & commits to it.

I'm the only developer, and no changes have been made to the actual 'master' in the meantime. I want to make the current state of the "release-1_5" branch the new master, and make 'master' the new working (HEAD?) branch, so that if I later do something like:

git checkout -b release-1_6

it will create a new branch that branches off from master

I know I could probably just keep doing "git checkout -b {new-branch-name}" (creating a linear branch-of-a-branch(-of-a-branch[-...]), but I'm pretty sure that would screw up Git's subway-like branch diagram.

If it matters, at the moment, the repo is entirely local, so there's no pulling/pushing or origin to worry about.

You're describing a simple merge of release-1_5 back onto master . Since master has no new commits, it'll be a fast-forward merge.

$ git checkout master
$ git merge release-1_5

And that's it. You can optionally delete the release-1_5 branch after that if you like.

I would not play with deleting branches.
What you want to do is to simply move latest commit from the release-1_5 to master .

git checkout master
git merge release-1_5
git checkout master
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.

Hope this helps

git checkout release-1_5
git merge --strategy=ours master  # This will keep content of branch
git checkout master
git merge release-1_5             # this will fast-forward master to the merge

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM