Git (ii): Git installation configuration and basic usage

Source: Internet
Author: User

installation of Git under WindowsOn the GIT home page http://git-scm.com/about can download the latest version of Git for your operating system, such as the one I'm currently using Git-1.9.4-preview20140929.exe.

GIT installation process, all the way to the default. Until this interface

 In order for us to perform the git operation in Windows CMD, we chose the second item. Next, you can do it by default. After the installation is complete, you can enter it in cmdgit--version, check that the current git is installed correctly. set up GitThe first thing you need to set is the User.Name and User.email values for the global variables. These two values are used to describe the current operation of the GIT operator and their contact, after you modify the code will leave your "footsteps."      "Global" means that these global variables work when you use any Git repository on this computer. Example below, in practice you have to replace your own name:git config--global user.name "Your name" git config--global user.email "[email protected]"By command git config, the user can provide this information to the local repository,--global is the meaning of the global configuration. Use the following command to check whether the above settings are successful:git config--global--listIn addition, we usually want to display the output of the command line in different colors depending on the type. You can set the following commands.
git config--global color.ui "always"On the command line, type:git help <command>, replace <command> with the specific command name you want to know. Git will display a description of the command in the user manual.
Create the first projectHere, for example, we use Git to record and track this project in a very small HTML project to demonstrate Git's basic operations.
To create a version libraryTo create a repository in Git, first decide where to store the project source code. In this example, to create a simple HTML page, the project is named MySite. First create a directory with the same name "MySite", and enter into this directory, and then enter the command git init. The whole process is as follows:$ mkdir MySite $ cd MySite $ git initCommand git init will create a. git directory. This directory is used to store all the metadata for the repository, the MySite directory as the working directory tree, and the code checked out from the repository.
Code ModificationNow it's time to add a file to the repository, and now we'll create a file named Index.html and add the title text "HTML World". The details are as follows: $ git add index.html $ git commit-m "add in Hello World HTML"The git commit command creates a commit record. A commit record is a history that is stored in a version, a record is created each time it is submitted, and the evolution of the code is marked.      Git adds the name and e-mail address of the submitter and submits the message to the submission record. The function of the parameter-m in the preceding command is to tell git that the message submitted is the add in Hello World HTML. For any version control system, appropriate written submissions are extremely important. It can explain the reason for the submission.

Run git log to see this commit-related information:


The first line of command git log output shows the commit name, which is the SHA-1 code that git automatically generates. Git uses it to track commits. Git uses this hash code to ensure that the name of each commit is unique, which is important in a distributed system.


working in a projectLearn how to handle file modifications below. There are no

After the modification, GIT can detect that the file has been modified. The command git status displays the status of the working directory tree, which is the current view state.

 The above output shows that Git has detected a modification, the modified file is listed under changed but not updated, and if it is to be submitted, it needs to be staged for modification. Staged modifications to prepare to commit the changes to the repository. There are three places in Git where you can store your code. The first is the working directory tree, which can be manipulated directly when editing a file. The second is the index, which is staging area (staging area). Staging area is a buffer between the working directory tree and the repository. The third, or final, version is the repository. Staging area is a modification that is ready to be submitted to the repository.

Look back at the command git add, which can stage the changes you just made to index.html, and it uses the same command to add a new file to the previous section, but this time it tells Git to track a new change instead of a new file.

 After staging the index.html, execute the commandgit statusAs you can see, the header in the output information has changed from changed but not updated into changes to be commited.      If the color switch is turned on, the index.html line changes from red to green. Next, you can use Git commit to commit the changes in the staging area.$git commit-m "Add - M "This allows-a more semantic document"Note that two-m parameters are used here. Git can accept the input of any number of times you submit a message, each time for another paragraph. command git log to quickly browse to submit a message.


A new parameter of command git log is introduced here-1. You can limit the number of commit entries for the command git log output by changing the number.


understand and use branchingA branch is a method of maintaining a parallel history in a project. In real-world applications, there are two branches that are useful: branches that support different releases of the project, and branches of development that support a particular feature (often referred to as topic Branch).      In this section, you'll describe the first type. The code for the current MySite project can be published, and at the same time, with branching, you can start the development of the next version of the new feature. A branch can keep a copy of the code to be published, so there is no need to stop the work being developed. The command to create a branch is GIT branch, which requires two parameters: a new branch name and a parent branch name. The newly created branch is based on the parent branch that already exists.$ git Branch rb_1.0 MasterThis command creates a branch called rb_1.0 from the main branch (Master branch). The main branch is the default branch of Git. The RB in the branch name represents the publishing branch (release branch).      This prefix allows you to quickly identify which branches are the publishing branch. Now let's make some new changes. These changes do not affect the code that is ready to be published. Add a link to the "Bio" page below, and add the following code before </body>: <ul> <li><a href= "bio.html" >biography</a></li > </ul> then use the following command to submit these changes:$ git commit-a-M "Add bio.html"The-a parameter tells Git to commit all the modified code. Now that you have the latest changes on the main branch and the original code on the release branch, switch to the publishing branch, the last modification before the most recent release. The command to switch branches is git checkout.$ git checkout rb_1.0Make the final changes before publishing: Add some descriptive meta tags to the $git commit-a-M "Add meta info" Handling PublicationsNow you're ready to release version 1.0, to label it. Tagging code in Git means tagging specific points in the repository's history so that you can easily find the appropriate version of the code in the future. Because it is to do 1.0 release, so hit a label named "1.0":$git Tag 1.0 rb_1.0The two parameters in the above command indicate the name of the label and the point where you want to label it, respectively, the tip of the 1.0 and rb_1.0 branches (the corresponding version, or the corresponding commit). git tag with the command without parameters can view a list of tags in the repository. Currently only shows the label just played 1.0:$git Tag1.0 Now you want to merge the changes made on the rb_1.0 branch into the main branch. The variable-base command git rebase can do the job. A variable is a change in one branch that is reproduced at the distal tip of another branch. Now the version tree as shown in (a), after the base of the version of the tree as shown in (b) figure.


First switch back to the main branch using Git checkout.$ git Checkout masterThen run the command git rebase, followed by a parameter: Want to base to which branch of the end, you use which branch name to do parameters.$ git rebase rb_1.0Now the repository is as shown in the (b) figure. Finally, as part of the collation work, delete the Publish branch rb_1.0. This may seem dangerous, but don't worry, the tag you just hit has been recorded at that time (as long as the label is still there, a series of commit records from the tag to the beginning of the version tree).      Deleting the branch only removes the name of the branch and does not delete any actual content on the branch. You can delete a branch by using git branch-d:$ git branch-d rb_1.0Deleted Branch rb_1.0. How do I patch a "1.0.x" branch in the future without publishing a branch? Simple, just create a branch from where you label it. The git branch command is still used this time, when the last parameter of the command is the parent branch name of the new branch, now only the name of the parent branch should be changed to the publication tag name. The command is as follows:$ git Branch rb_1.0.1 1.0 $ git checkout rb_1.0.1Switched to Branch "rb_1.0.1" The last thing you do with Git is to create an archive for your code release. Typically, it is sufficient to package the version content of the label into a single tar package or ZIP package. Typically packaging operations in a project can be done using MAVEN, so there's no introduction to archive packaged with Git.
cloning a remote repositorySo far, we've been working on the local repository, not yet the remote repository.      In addition to the previous features, Git can work with the remote repository to share local effort, or to replicate other repositories locally.      To work with a remote repository, start by cloning a remote repository with the command git clone, which creates a full copy of the remote repository locally. Share all copies of MySite items in this book on GitHub (a Web site that provides a git repository hosting service), and you can use Git clone to clone them locally.$ git clone git://github.com/tswicegood/mysite.git mysite-remoteThe command git clone has two parameters: the location of the remote repository and the local directory where the repository resides. The second parameter is optional, but I already have a wysite directory on my local, so I need to provide a second parameter to specify the destination directory for the remote repository copy. More parameters are covered in later chapters, but in most cases these two parameters are sufficient. In a later chapter, git pushes local changes into the remote repository and changes from the remote repository.


Git (ii): Git installation configuration and basic usage

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.