Git use has become common in team development, and bloggers often use coding, Github and other code-hosting platforms. In collaborative development, we often encounter such A problem: after local development, A pushes the code to the remote, at this time, the version of B’s local code is lower than the version of the remote code, at this time, how should B pull the latest code from the remote and merge it with its own local code? The specific steps are as follows:
- View remote warehouse:
git remote -v
Copy the code
- For example, in step 1, we check that there is a remote repository called Origin. We can use the following command to get the latest version of the code from the Origin remote repository
git fetch origin master:temp
Copy the code
Download the temp branch from the master branch of the remote Origin repository to the master branch and create a new temp branch
- View the difference between the Temp branch and the original local branch
git diff temp
Copy the code
- Merge the Temp branch with the local master branch
git merge temp
Copy the code
Now, B’s local code is in the same version as the remote repository, so B can coding happily.
- Reset add before commit
2) git reset --mixedCopy the code
As a final note, we created the temp branch in the previous step. If we want to delete the temp branch, we can do so:
git branch -d temp
Copy the code