Learn git, use Git②

Source: Internet
Author: User

Previously, Git's core features game archived local version management was introduced. This will introduce the remaining two core features of git: branching and remote repositories .

1.Git Game Archive Evolution version--git Branch

The idea of git branching is interesting, and git allows us to copy one or more new game menus from the existing Game Archive menu (remember this metaphor), which will inherit the previous archive and file, and on each game menu you can proceed with the file-reading operation, and, even worse, Continue the game on the newly created Game archive (continue to work), after the storage and access, you can also directly discard the game archive or instantly with the original game archive "merge"!. Think of what use, you open the game to play the main line of the game, suddenly found that there are two copies of the task immediately to the deadline, you temporarily difficult to get out, but also reluctant to two copies of the task handsomely paid, so you ask two good friends and you use Git, you pulled two branches to them, Let them play a copy, after the end of the merger of two people branch, for a moment, you have the main story of the experience, but also obtained two copies of the money and experience of the reward, wow, quickly embark on the pinnacle of life, is so magical.

Of course, there are accidents, you have an unreliable good base in the copy of the Dead 100 times, your hard to save all the equipment has not, when the good friends are discouraged, you quickly deleted his game branch, when everything has not happened on the good, you dashing to him to smile. It's so easy.

Thousand calculate million or a mistake, good base friend in hit copy 1 when use your only return scrolls, and back to the scroll in good base friend 2 there still, now you want to start merging branches, but Git reminds you git is good but can not violate the law of nature, ask you to deal with this logic contradiction, you don't panic, You get a good base friend 2 of the game Archive, contrast, found that there is only one difference, is the number of scrolls back to the town, so you tell git, this back scroll I don't want to, merge branches again, success!

Do you understand me? So you've almost learned the meaning of the Git branching feature, and to avoid forgetting, I'm here to help you with a simple comb:

(1) When developing a new feature, you can pull a branch from the Master branch, where you can enjoy all the file resources of the main branch, on the one hand, develop new functional modules independently, if the development is successful, merge branches, add functionality, if development fails, delete branch, everything will be as never happened.

(2) receive another task while working on a branch, save the Workbench (which will tell you what to do later), open a new branch to complete the task, merge, go back to the branch, resume working.

(3) when more than one person is working together, git checks to see if the branches are in conflict with the main branch, for example, branch 1 is based on a file that modifies the main branch, but branch 2 is based on the source file of a file, then git will let you handle the error and then merge.

Well, here's a general idea of how git branching works, and now we're going to show you the specific instructions:

(1) Create branch:$ git branch <branch name>

(2) Switch branch:$ git checkout <branch name>

(3) Create and transfer to branch:$ git checkout-b <branch name>

(4) View branch:$ git Branch

(5) Delete branch:$ git checkout-d <branch name>

(6) Forcibly Delete branch:$ git checkout-d <branch name>

(7) Merge branch:$ git merge <branch name>(merge a branch into the current branch)

(8) View Branch Merge chart:$ git log--graph

(9) Save the Job site:$ git stash

(10) Restore work site:$ git stash pop

Hopefully you can understand that branching is a good thing, but you need to know when to use it and when not.

2.Git Remote Storage

After introducing the powerful branching feature of Git, we went on to introduce git another powerful feature, remote repository.

In fact, the name can be justified, that is, Git allows us to push the GIT repository to remote, what is the benefit of it? There are mainly the following two aspects:

    1. File security is guaranteed: do not worry because of computer failure caused by the loss of files, even if someone has changed the remote warehouse files, each relevant personnel will have a local warehouse backup, as long as the re-submission is good;
    2. Easy to co-development: Through the powerful branch function, can be many people from the remote warehouse to pull down the branch, the development of different functions, each other, improve the efficiency;

GIT remote repository management and local warehouse indistinguishable, so here's just a brief description of the GIT directives related to remote repositories:

(1) Local warehouse associated to remote:$ git Remotes add Origin <url>

(2) Clone remote repository to Local:$ git clone <url>

(3) View Remote Library information:$ git remote-v

(4) Update files from remote repository:$ git pull

(5) Push local modifications to the remote repository:$ git push (push to Master branch and merge by using-U Origin master)

Wait, it's not over, I said branch remote warehouse and multi-person development. There should be a couple of related git instructions that need to be accounted for:

Since locally created branches are not visible to others if they are not pushed to the remote, we are also familiar with several git directives for pushing local branches:

(1) Push branch from Local:$ Git push origin <branch-name>(if push fails, you need to crawl remote new commits with git pull first)

(2) Create a local branch corresponding to the remote branch:$ git checkout-b <branch name> origin/<branch name>

(3) Establish the association of local and remote branches:$ git branch--set-upstream <branch-name> origin/<branch name>

Okay, so far I've finished with Git's important instructions and their implications. This article has made me start over the relevant knowledge point, also hope to you also helpful.

(_[~_)

Learn git, use Git②

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.