Git merge master into feature branch

后端 未结 11 656
既然无缘
既然无缘 2020-11-27 08:56

Let’s say we have the following situation in Git:

  1. A created repository:

    mkdir GitTest2
    cd GitTest2
    git init
    
  2. Some m

相关标签:
11条回答
  • 2020-11-27 09:22

    I am on the feature branch and made refactorings. I want to merge the master changes now to my feature branch. I am far behind. Note I do not want to pull the master changes to my local because my feature branch have modules moved from one place to another. I found just performing below without pull does not work. it says "Already up to date."

     //below does not get the latest from remote master to my local feature branch without git pull
        git checkout master 
        git fetch 
        git checkout my-feature-branch 
        git merge master
    

    This below works, note use git merge origin/master:

     git checkout master 
        git fetch 
        git checkout my-feature-branch 
        git merge origin/master
    
    0 讨论(0)
  • 2020-11-27 09:22
    In Eclipse -
    

    1)Checkout master branch

    Git Repositories ->Click on your repository -> click on Local ->double click master branch
    ->Click on yes for check out
    

    2)Pull master branch

    Right click on project ->click on Team -> Click on Pull
    

    3)Checkout your feature branch(follow same steps mentioned in 1 point)

    4)Merge master into feature

    Git Repositories ->Click on your repository -> click on Local ->Right Click on your selected feature branch ->Click on merge ->Click on Local ->Click on Master ->Click on Merge.
    

    5)Now you will get all changes of Master branch in feature branch. Remove conflict if any.

    For conflict if any exists ,follow this -
    Changes mentioned as Head(<<<<<< HEAD) is your change, Changes mentioned in branch(>>>>>>> branch) is other person change, you can update file accordingly.
    

    Note - You need to do add to index for conflicts files

    6)commit and push your changes in feature branch.

    Right click on project ->click on Team -> Click on commit -> Commit and Push.
    

    OR

    Git Repositories ->Click on your repository -> click on Local ->Right Click on your selected feature branch ->Click on Push Branch ->Preview ->Push
    
    0 讨论(0)
  • 2020-11-27 09:29

    git merge

    you can follow below steps

    1. merge origin/master branch to feature branch

    # step1: change branch to master, and pull to update all commits
    $ git checkout master
    $ git pull
    
    # step2: change branch to target, and pull to update commits
    $ git checkout feature
    $ git pull
    
    # step3: merge master to feature(⚠️ current is feature branch)
    $ git merge master
    
    

    2. merge feature branch to origin/master branch

    origin/master is the remote master branch, while master is the local master branch

    $ git checkout master
    $ git pull origin/master
    
    $ git merge feature
    $ git push origin/master
    
    
    0 讨论(0)
  • 2020-11-27 09:33

    You might be able to do a "cherry-pick" to pull the exact commit(s) that you need in to your feature branch.

    Do a git checkout hotfix1 to get on the hotfix1 branch. Then do a git log to get the SHA-1 hash (big sequence of random letters and numbers that uniquely identifies a commit) of the commit in question. Copy that (or the first 10 or so characters).

    Then, git checkout feature1 to get back onto your feature branch.

    Then, git cherry-pick <the SHA-1 hash that you just copied>

    That will pull that commit, and only that commit, into your feature branch. That change will be in the branch - you just "cherry-picked" it in. Then, resume work, edit, commit, push, etc. to your heart's content.

    When, eventually, you perform another merge from one branch into your feature branch (or vice-versa), Git will recognize that you've already merged in that particular commit, know that it doesn't have to make it again, and just "skip over" it.

    0 讨论(0)
  • 2020-11-27 09:34

    Complementing the other answers, as these commands are recurrent we can do it in a row (given we are in the feature branch):

    git checkout master && git pull && git checkout - && git merge -
    

    Or add them in an alias:

    alias merge_with_master="git checkout master && git pull && git checkout - && git merge -"
    
    0 讨论(0)
提交回复
热议问题