Git branch notes

Source: Internet
Author: User

1. The branch in git is essentially a variable pointer to a commit object. Git uses master as the default branch name.

2. Run the GIT branch command to create a new branch, but it does not automatically switch to the Branch. Therefore, in this example, we still work in the master branch.

3. to switch to another branch, run the GIT checkout command.

4. When two branches modify a file at the same time, a conflict occurs. In this case, refer to Chapter 3 of git pro to solve the problem. Copy to the following link:

Http://blog.csdn.net/xzongyuan/article/details/9381001

5. Check the remote Branch
If the contributor has its own git repository and pushes the changes to the repository, you can add the repository as a remote branch after obtaining the repository access address and the name of the corresponding branch, then merge them locally.
For example, Jessica sent an email saying that a great new function has been implemented on the ruby-client branch in her code library. I hope we can help test it. We can add her warehouse as a remote warehouse and then capture
After the data is retrieved, check out the Branch she said to the local device for testing.

$ git remote add jessica git://github.com/jessica/myproject.git$ git fetch jessica$ git checkout -b rubyclient jessica/ruby-client

If she sent an email again soon, saying that there is another great feature to be implemented on another branch, we just need to re-capture the latest data and then check that branch to the local, you do not need to set up a remote repository repeatedly.
This approach facilitates long-term cooperation with others. But the premise is that the contributor has its own server, and we also need to create a remote branch for everyone. Some contributors do not submit code patches frequently, so it is more efficient to receive patches by mail. At the same time, we do not want to build hundreds of branches, but we only need to take one or two patches from each branch. However, you can simplify this process if you use a script program to manage the service or directly use the code repository to host the service. Of course,
The method you select depends on your and contributor's preferences.
Another advantage of using remote branches is that the submission history can be obtained. No matter whether there is a problem with code merge, at least we know the historical forks of the branch, so by default, the three-way merge will be automatically started from the common ancestor, without the need to select-3
And do not pray that a common benchmark exists like a patch.

If you only need temporary cooperation, you only need to use the GIT pull command to capture the data in the remote warehouse and merge it to the local temporary branch. A one-time crawling operation naturally does not add the repository address as a remote repository.

$ git pull git://github.com/onetimeguy/project.gitFrom git://github.com/onetimeguy/project* branch HEAD-> FETCH_HEADMerge made by recursive.

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.