Basic commands about Git

Source: Internet
Author: User

The GIT environment is not built here first. This article is primarily a command used by common developers in the development process.

  

For developers, you configure a personal client after someone builds a git server:

Set GIT configuration variables, this is a one-time job. That is, these settings make permanent records in the global file (. gitconfig) in the user's home directory.

this. gitconfig file does not follow the. git folder to make changes. Instead, the. config file is changed each time it is set.

git config--global user.name "yourname"
git config--global user.email "[Email protected]"

This place I'm talking about the initialization of the Git repository problem:

The general initialization operation is the GIT init command.

However, this warehouse is generally initialized to the cmd default path.

My one is cmd. Open default is C:\users\kongxiaohan>

If the git init command initializes the repository on Git brash, the generated. Git folder is generated on the c:\users\kongxiaohan> path.

The repository for Git is c:\users\kongxiaohan> in this Kongxiaohan folder.

Many programs are placed in this folder by default. Inconvenient, it is recommended to select a different folder.

For example, I set up a folder (git) as a git repository on D disk.

In Git brash

CD D:

CD git (if there is no Git folder at this time on the D drive, use the mkdir git command)

Git init has successfully built a git repository in the D-Drive Git folder.

this. Git directory is the Git repository. (also called warehouse, repository)

The folder where the. Git folder is located (I'm git here) is called the workspace.

Set up aliases in Git so that the more concise subcommands can be applied.

Add an alias for the git command in this user's global configuration:

$ git config--global alias.ci commit

$ git config--global alias.st status

$ git config--global alias.co check

$ git config--global alias.br branch

Turn on the color display in the git command output (temporarily without realizing the effect of this configuration)

$ git config--global color.ui true

My project is shared on GitHub to find the path to the corresponding project.

Checkout warehouse (with git clone command):

Is the state of the GIT brash after the item is checked out (being checked out).

Clone complete (preferably a small project clone, otherwise it takes too long)

Add files to git.

1. Add a fixed file git add xxxx.xxx (followed by file name)

2. Add all the files to git Add. (All files)

3. Add a class of files git add *.docx (add all the files at the end of the. docx file)

The representation that applies to this wildcard character.

Here are a few things to add to the workspace. Create a welcome.txt in the workspace, with the content "Hello world" in one line

Execute command

$ echo "Hello World" >welcome.txt

This has a HelloWorld in a welcome.txt file in the workspace.

Add this newly created file to the repository

$git Add Welcome.txt

It's not over here. A commit operation is required as well as SVN. But unlike SVN, you have to write a commit when committing. This requirement for

Git is mandatory. Do not accept blank commit instructions as SVN does. When git commits, it does not provide a submission description (that is, using the-m parameter) when it is committed on the command line. Git will open automatically

Editor that asks you to enter a submission description in it, save and exit after you have entered it. This place is because it is the input of the submitted information in the Vim editor.

So you have to master some of the editing techniques of vim or Emacs (two common editors used under Linux). Otherwise saving and exiting can also be a problem. (I tried, I didn't fix it ...) Do not know how to save and exit ..... I'm so embarrassed .... Have time to do it again)

Submit below. To facilitate the instructions, use the-m parameter to give the submission instructions directly.

$ git commit-m "initialized"

Feedback:

From the above command and output can be seen:

This submission was submitted on the master's branch. (If the first commit of the branch will have (Root-commit)) The ID submitted is B78BBDF.

As you can see from the second line, this commit modifies a file that contains 0 rows of insertions. 0 deletions.

As you can see from the third line, this submission creates a new file Test7.txt

Why is there a. git in the workspace root directory?

Commit the file to git.

The commit command for git is: git commit

Here's a bit of git commit and git commit-a.

Git commit commits the contents of staging area, which is the file in changes to be committed.

Git commit-a submits files in changes bu not updated in addition to the files in the staging area.

Add submission Information

If you run Git commit (-a) directly, the description will be added by default with VI. You can also use git config --global core.editor the command to change to your favorite editor. Another way is to add the commit information directly using the-M option.

Basic commands about 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.