Git: Push rejected

前端 未结 1 550
野性不改
野性不改 2021-01-20 18:20

I have a team and we are working on a project. One of our teammembers created a repository on GitHub and add others as collaborators. My team member committed our code to th

相关标签:
1条回答
  • 2021-01-20 18:33

    Looks like your two master branches have diverged.

    # HEAD at your master
    $ git checkout master
    
    # your master on a new branch
    $ git checkout -b diverged.master
    
    # get origin's master
    $ git checkout master
    $ git fetch origin master
    $ git reset --hard origin/master
    
    # Create a new branch for the diverged feature
    $ git checkout -b feature.branch
    
    # Merge your diverged changes into the new feature branch
    $ git merge diverged.master
    
    # Do any conflict resolutions
    
    # Merge feature branch to master
    $ git checkout master
    $ git merge feature.branch
    
    # Push to remote
    $ git push origin master
    

    Edit

    I missed the part about this being a brand new repo.. makes this slightly easier

    # HEAD at your master
    $ git checkout master
    
    # your master on a new branch
    $ git checkout -b diverged.master
    
    # delete master branch
    # git branch -D master
    
    # pull master from origin
    $ git pull origin master
    
    # HEAD at origin's master
    $ git checkout origin master
    $ git pull # for good measure
    
    # merge your changes
    $ git merge diverged.master
    
    # push your changes
    $ git push origin master
    
    0 讨论(0)
提交回复
热议问题