简体   繁体   中英

Git workflow: Merge existing branch to new branch and delete old one

It was a stupid question. Sorry for deleting, but it wouldn't be helpful for anyone.

To change new_branch checked out from target_branch (or master you can use same method):

git checkout target_branch
git cherry-pick target_branch..new_branch
git branch -f new_branch
git checkout new_branch

Note:

-If there has cherry-pick conflicts, you can modify and save the conflict files, then use git add . and git cherry-pick --continue . -If you don't want to rebase n ew_branch on the top of target_branch , you can use git checkout <an history commit of target_branch> , and then use above commands to rebase new_branch . As below graphs, if you use git checkout B, and after above commands, the branches will look like:

# Original branch structure

    A---B---C target_branch

    D---E---F new_branch

# After rebase new_branch from commit B

    A---B---C target_branch
         \
          D'---E'---F' new_branch

To Resolve your issue, Go through below steps :

  1. git checkout target_branch
  2. git merge new_branch
  3. git push origin target_branch

You are now at target_branch , Let's Delete Old Branch : new_branch

  1. git branch -D new_branch
  2. git branch new_branch

Now you & your friend can make new branches from target_branch & work on new_branch

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