• git merge [branch-name] Merge a branch into the current branch, which will merge the merged branch and your current branch’s commit together to form a new commit
  • git rebase [branch-name] Merge a branch into the current branch, putting your current branch’s commit at the end of the merged branch
  • git rebase -i HEAD~[num] merge the last num commits into one (so that there is only one commit after pushing to the remote repository, avoiding contaminating the remote commit)
  • git pull --rebase is equivalent to git fetch + git rebase
  • git checkout <branch-name> [--] <file-name> pulls the current file from a different branch
  • git checkout --theirs [file-name] means check out the other branch, i.e. save the changes from the other branch and discard the changes from the current branch. In case of conflict, use someone else’s code directly
  • git checkout --ours [file-name] Check out the current branch, i.e. save the changes in the current branch and discard the changes in the other branch. Use your own code directly in case of conflicts
  • git cherry-pick <commit-id1> <commit-id2> ... Merge some of the specified commits into the current branch
  • git cherry-pick <branch-name> Move the most recent commits from the selected branch to the current branch
  • One merge operation
    git checkout dev
    git rebase master
    #or git merge master
    #or git cherry-pick 8797a4f
    #or git merge master #or git cherry-pick
    git add .
    #continue to modify the merge
    git rebase --continue
    #or git merge --continue
    #or git cherry-pick --continue
    #If you don't want to merge, just terminate
    git rebase --abort
    #or git merge --abort
    #or git cherry-pick --abort
    git merge and git rebuild
    
  • Suggestions for using git merge and git rebase
    Use merge for public branches, rebase for personal branches
    local and remote branches are the same, use rebase instead of merge