Git adventures (3): create a local repository of your own (1)

Source: Internet
Author: User

BKJIA Editor's note: This is the third article translated by the translator LIU Hui on the series of articles "Git Community Book". This article uses the "ding Jie niu" method to introduce how to add a project to version management. If you are not clear about how to download, install, and configure Git, refer to the Git adventures (2): install and configure Git. The following is the text of this article.

If you want to add a project to Git version management, you can use the git init command to create an empty local repository in the directory where the project is located, then, use the git add command to add them to the stage or index in the local Git repository, and then use the git commit command to submit them to the local repository.

Create a new project directory and generate some simple file content:

$ mkdir test_proj$ cd test_proj$ echo “hello,world” > readme.txt

Create a new local repository in the project directory and add and submit all the files in the project to the local repository:

$ Git init # create an empty local repository Initialized empty Git repository in/home/user/test_proj/in the current directory /. git/$ git add. # add all the files in the previous directory to the temporary storage zone $ git commit-m'project init '# create and submit [master (root-commit) b36a785] project init1 files changed, 1 insertions (+), 0 deletions (-) create mode 100644 readme.txt

Git directory structure

The git init command creates a directory named ". git" in the top-level directory of the Project. Its alias is "Git directory ). At this time, although there are some files in the "Git directory", there is no commit in it, so we call it an empty repository (empty Git repository ).

Unlike SVN, a Git project generally only creates a ". git "directory, while SVN will create ". svn "Directory; this is also one of the reasons I like Git :)

Git stores all historical commit information in the "Git directory", which is the repository of a Git project; after you edit and modify the local source code, the created submission will be saved first, and then pushed to the remote server. When we copy the project directory and the "Git directory" together to another computer, it works right away (all the submitted information is saved in the Git directory ); you can even copy the "Git directory" only, but check it again.

To facilitate debugging, Git can specify the location of the Git directory of the project. There are two methods: one is to set the "GIT_DIR" environment variable, and the other is to set the "-- git-dir" parameter in the command line to specify its location, let's take a look at this (git (1) Manual Page ).


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.