Make the current Git branch a master branch

前端 未结 14 1874
悲&欢浪女
悲&欢浪女 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:21

    The solutions given here (renaming the branch in 'master') don't insist on the consequences for the remote (GitHub) repo:

    • if you hadn't push anything since making that branch, you can rename it and push it without any problem.
    • if you had push master on GitHub, you will need to 'git push -f' the new branch: you can no longer push in a fast forward mode.
        -f
        --force
    

    Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care.

    If others have already pulled your repo, they won't be able to pull that new master history without replacing their own master with that new GitHub master branch (or dealing with lots of merges).
    There are alternatives to a git push --force for public repos.
    Jefromi's answer (merging the right changes back to the original master) is one of them.

    0 讨论(0)
  • 2020-11-22 06:23

    Rename the branch to master by:

    git branch -M branch_name master
    
    0 讨论(0)
提交回复
热议问题