Obtain the latest code from the remote repository and merge it to the local branch.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.