Git entry: initialization, simple use, Branch

Source: Internet
Author: User

The introduction of git is not much said. Here is just a simple entry-level operation.
How to install, initialize, and perform simple operations and branch operations.
Everything is simple, not reasonable, but simple operations.
Original article, if reproduced, please indicate the source: http://blog.csdn.net/yihui823/article/details/6673804

I. Preparation 1. Installation

Under Ubuntu:

Sudo apt-Get install git

Sudo apt-Get install gitk

 

Windows:

Msysgit

 

2. How many steps does initialization + put the elephant in the refrigerator?

1. open the refrigerator door.

2. Put the elephant in

3. Close the refrigerator door

 

+ How many steps do I need to manage a directory using git?

1. CD [Directory]

2. KNOCK: git init

3. Press enter.

 

2. Start to use 1 and check the content of the current database with simple control

Git status

Add a new file

Git add [file1] [file2]

Submit to version Library

Git commit-M "[Message]"

Here we are talking about the standalone version, that is, the commit to the local version library.

If the managed directory is deleted, the Code cannot be found.

Here, the commit is equivalent to backing up a version image of the current Code.

If you have any questions in the future, you can easily compare them and perform regression.

2. Branch

The concept of branch is hard to say and simple.

Branch

Summarized some application scenarios of the Branch:

1. Research

2. Multiple products based on a set of versions

3. The two sets of code developed in parallel must be merged.

4. You want to write the experiment code yourself.

5. When you want to use

As you can see, the Branch is mainly used for multiple sets of code.

At the beginning of coding, people like to keep a lot of code on the machine. One is for reading, the other is for writing, and the other is for copying from others, one set is self-written lab code, and so on. In case of carelessness, it is easy to confuse.

Instead, the branch Function of git can be used to store so many sets of code in only one working directory.

After switching the branch, you only need to refresh it in eclipse. You do not need to create a bunch of projects, and then wait for an error in the dark. However, it is convenient to compare and Merge multiple branches.

 

How to Use the branch

* View Branch Information

Git Branch

* Create a branch

Git branch [new branch]

This is created based on the current branch. The current Branch, in short, refers to the code of the last commit.

By default, the system has a master branch.

* Switch to Branch

Git checkout [target branch]

For example:

At the beginning, we saw git Branch:

* Master

Indicates that there is only one branch, Master

Then, we create a new branch:

Git branch new1

Then execute git Branch

You can see

* Master

New1

It indicates that there are two branches, and the current branch is on the master.

Finally, we switch the branch git checkout new1.

We can see that

Master

* New1

No.

* Delete A branch

Git branch-d [branch name]

(Cannot be deleted? Use this !)

Git branch-d [branch name]

 

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.