There are two methods.
1. Git pull: Get the latest code locally and automatically merge it to the current branch.
Command display
// Query the current remote version $ git remote-V // pull and merge the latest code $ git pull origin master [Example 1: pull the remote origin/Master branch and merge it to the current branch] $ git pull origin Dev [Example 2: Pull the remote origin/dev branch and merge it to the current branch]
Analysis: This method is not recommended because it is directly merged and cannot handle conflicts in advance.
2. Git fetch + merge: Get the latest code to the local device, and then manually merge the branches.
2. 1. Create additional local branches
Code display
// View the current remote version $ git remote-V // obtain the latest code to the local temporary branch (the local current branch is [branch], the obtained remote branch is [origin/branch]) $ git fetch origin master: master1 [Example 1: Create a master1 branch locally, download the remote origin/Master branch to the master1 branch] $ git fetch origin Dev: dev1 [Example 1: Create a dev1 branch locally, download the remote origin/dev branch to the dev1 branch] // view the version Difference $ git diff master1 [Example 1: view the version differences between the local master1 Branch and the current branch] $ git diff dev1 [Example 2: view the version difference between the local dev1 Branch and the current branch] // merge the latest branch to the local branch $ git merge master1 [Example 1: merge local branch master1 to current branch] $ git merge dev1 [Example 2: Merge local branch dev1 to current branch] // Delete local temporary branch $ git branch-D master1 [Example 1: delete local branch master1] $ git branch-D dev1 [Example 1: Delete local branch dev1]
Note: This method is not recommended and additional processing of temporary branches is required.
2. No additional local branches are created
Code display
// Query the current remote version $ git remote-V // obtain the latest code locally (the local current branch is [branch] and the obtained remote branch is [origin/branch]) $ git fetch origin master [Example 1: Get the remote origin/Master branch] $ git fetch origin Dev [Example 2: obtain the remote origin/dev branch] // view version differences $ git log-P master .. ORIGIN/Master [Example 1: view the version difference between the local master and the remote origin/Master] $ git log-P Dev .. ORIGIN/dev [Example 2: view the version difference between local Dev and remote origin/dev] // merge the latest code to the local branch $ git merge origin/Master [Example 1: merge remote branch origin/master to current branch] $ git merge origin/dev [Example 2: Merge remote branch origin/dev to current branch]
Source: csdn
Original: 79162130
Obtain the latest code from the remote repository and merge it to the local branch.