Local branch behind remote branch (pull, rebase, fetch, merge)

后端 未结 1 2028
名媛妹妹
名媛妹妹 2021-01-07 08:04

If I am working on my branch, branch1 and then I push some commits while my team member was also working on branch1--when it comes time for my team

相关标签:
1条回答
  • 2021-01-07 08:09

    git pull origin/branch1 && git merge origin/branch1

    git pull

    git pull is actually an alias to those 2 commands: git fetch + git merge so your second part of the command is useless.


    The way to grab changes is this - Several option:

    # Update your local repo with the latest code:
    git fetch --all --prune
    
    # Merge the changes (you already did a pull)
    git merge origin branch1
    

    OR:

    # grab & merge the latest changes into your current branch 
    git pull origin branch1
    

    rebase

    If you want your changes to be on top of the other changes then you can use the --rebase flag when pulling the content.

    # As before - update your local repo with the latest code:
    git fetch --all --prune
    
    # Merge the changes with the rebase flag
    git pull --rebase origin/branch1
    

    Image src: http://blogs.atlassian.com/


    Stash + rebase automatically

    You have those config which you can set:

    rebase.autoStash + pull.rebase

    rebase.autoStash

    When set to true, automatically create a temporary stash before the operation begins, and apply it after the operation ends.
    This means that you can run rebase on a dirty worktree.

    However, use with care: the final stash application after a successful rebase might result in non-trivial conflicts. Defaults to false.

    pull.rebase

    When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run.

    git config pull.rebase true
    git config rebase.autoStash true
    
    0 讨论(0)
提交回复
热议问题