Make the current Git branch a master branch

前端 未结 14 2148
悲&欢浪女
悲&欢浪女 2020-11-22 05:29

I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.

Then, tens of commits later, I realized the branch is in muc

14条回答
  •  梦如初夏
    2020-11-22 06:18

    I found this simple method to work the best. It does not rewrite history and all previous check-ins of branch will be appended to the master. Nothing is lost, and you can clearly see what transpired in the commit log.

    Objective: Make current state of "branch" the "master"

    Working on a branch, commit and push your changes to make sure your local and remote repositories are up to date:

    git checkout master      # Set local repository to master
    git reset --hard branch  # Force working tree and index to branch
    git push origin master    # Update remote repository
    

    After this, your master will be the exact state of your last commit of branch and your master commit log will show all check-ins of the branch.

提交回复
热议问题