Git is a simple getting started tutorial. It is a simple tutorial for students who have never dared to use Git.

Source: Internet
Author: User

Git is a simple getting started tutorial. It is a simple tutorial for students who have never dared to use Git.

It has been almost half a year since I started to work in February 12, 2014. I still remember the surprise when I first came into contact with the centralized version control tool SVN. This is for me who have been developing it independently, only then can the original code be managed like this! Of course, the current understanding of SVN is nothing more than knowing the operating principle and satisfying some simple code version control in the work. I have heard about Git, a version control tool, for a long time. I also understand the differences between Git and SVN, and I have always wanted to get started with it, however, some of the textbooks that have suffered from downloading are too thick and contain too much content. Just in the past few days, the incident was quite plentiful, so I found some relevant information and began to get started with Git. I hope to get started with my classmates!

Let's get started later!

1. Download and install Git

I'm using the installation package http://www.cr173.com/down.asp for this URL? Id = 30724

You can also download the git Chinese installation package from other websites.

Because Git is relatively simple to install, I just want to focus on the interface that is not mentioned and keep it by default.


The following figure shows how to install the Git software.


The following page is used to select which components to install and retain the default value.



Select the version to install. Just install the Git Bash version.




Select the default Interface.




The installation is successful.




Open Git Bash in the Start Menu. If this interface is displayed, it indicates that Git has been installed successfully.





2. Create a Git version Library

Git is a distributed version control tool, while SVN is a centralized version control tool. To be clear, if SVN is used for version control, we first need a server as the SVN version server. When submitting the operation, SVN synchronizes our local code to the SVN server. That is to say, the SVN server has the code of each updated version, but on the computer where we write the code locally, only the latest version is saved. Therefore, if the SVN server fails, the previous version records may be lost.

Git adopts a distributed strategy. That is to say, Git not only stores records of different versions on the server, but also stores records on the local disks of each computer that uses Git, it also saves version record files. Therefore, we can implement offline version submission. When we can connect to the Internet, we can submit the local version library to our Git server. So the working principle of Git and SVN is different, other differences between the two tools, you can look at this article http://blog.csdn.net/yihui8/article/details/6445847

Next, we will introduce the simple use of Git. Although some Linux commands are required, don't be afraid.

First, we need to create several folders to simulate our use environment. Because I only have one computer, my computer serves as a Git server and a Git user. Therefore, we create the following document structure to simulate our use environment.



Develop: it is the folder where we need to store code. Here, it stores the code files we have written that require version control.

Git: This is the installation folder of our Git software. It is placed here for the convenience of the diagram.

Repository. This folder is used to store version files on the server.

After creating these folders, we first need to create an empty version control library in the folder on the server.

Open our Git Bash and enter the following command



In this way, an empty version library named share. git is created under our directory.

After the version library is created, we can see the following file structure, which indicates that the version library is successfully created.

After creating the version library, open the Develop folder and create two folders user1 and user2. We use these two folders to simulate the two users who use Git.

First, right-click user1 and select git bash. Then, the command line window in the directory where user1 is located is opened.

Then input git clone/e/Repository/share. git/

In this way, we copy the version library on the server to the local machine. We can see an additional share folder under our user1 folder, which is the version library we copied, we can put the code we need to manage under the share directory for version control.


Next, we use the echo syntax to write "Hello Git" in the index.txt file"

Run the cat command to check whether the text is successfully written.


After successful writing, we can include this file into our version library. However, before joining the version library, we need to create a user to submit the file to the server version library.

Run the following command to create a user:


After creating the user, execute the git add index.txt command. First, add index.txt to our version control, then execute git commit index.txt, and submit the modification to our local version library.


After this is done, the following interface will appear, which uses the VIM text editor to write the comments of the submitted version.

VIM is a frequently used editor in linux. After this interface is displayed, click I to enter the insert mode. After writing the comments, click esc to exit the insert mode and return to the command mode. Enter: wq, save the changes and exit. In this way, our files are submitted to the local version library.


Note that we only use the commit command to submit our files to our local version library, the version library on the server, and there is no information available. Therefore, we also need to submit our files to the server version library. What should we do?

Enter git push origin master

Using the push command, we will submit our version Library to the master branch on the server. The origin represents the address of our server version library.

After the submission is successful, other users can download the server version library pull for collaborative development.




Git Quick Start

We recommend that you take a look at the Git authoritative guide. This book is widely used by many people, including beginners. The content is comprehensive and unanimously recognized by professionals. If you are interested, please pay attention to it.

Continuous integration [git] When git is used for collaborative development projects

To use version management, such as git and svn, you must manually obtain the latest resources on the server.

Related Article

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.