How to move the current working branch to master branch in git

后端 未结 10 1003
挽巷
挽巷 2020-12-13 00:13

I have currently one of the project it contain more branches. master branch not yet merger long time. So i want switched to master with latest code.

Can you please g

相关标签:
10条回答
  • 2020-12-13 00:59

    Do you want to merge a 'develop' branch into master?

    git checkout master
    git merge develop
    

    Or do you want to merge the changes from master into your development branch?

    git checkout develop
    git merge master
    
    0 讨论(0)
  • 2020-12-13 01:01

    If I understand your English correctly, you don't want to merge your changes back into master, but just reset master to point to the latest commit in your currently checked out branch? To do this, use:

    git branch -f master
    
    0 讨论(0)
  • 2020-12-13 01:01

    If you want to take some commits from branch to master, you could use cherry-picking.

    This takes only certain commits from branch to master, but is – of course – not guaranteed that no conflicts occur.

    See my answer to Managing hotfixes when develop branch is very different from master?

    However, if you want to take all commits from branch into master, you won't get around merging and resolve conflicts (unless you git reset --hard other-branch the master branch as described – and discouraged – by Mark).

    0 讨论(0)
  • 2020-12-13 01:04

    In IntelliJ at least, you can do the following:

    1. Checkout the branch to merge into master.
    2. VCS->Git->Merge Changes
    3. Select master
    4. Change the strategy to "ours"
    5. Select "No fast forward."
    6. Click "merge"
    7. Commit (may not be needed)
    8. Push

    This turns master into your current branch. The history for master is preserved. I'm sure there is a git command line equivalent.

    0 讨论(0)
提交回复
热议问题