Git Initialize Repository

Source: Internet
Author: User

create a repository with workspaces

When you start a new project, you first create and initialize the code base. If it is in the working directory of this machine, then:

$ git init

It's enough. If the repository you want to initialize is not in the current directory, you need to specify the directory where the repository is located for the git init command:

$ git init hello

After executing the command, a directory named. Git is created in the current directory or under the directory you specified, which is the repository.

Repositories with workspaces are used primarily for daily work. It works by committing the code to the local repository and then pushing it to the repository on the server through the local library.

Create a bare version library

With respect to the repository with workspaces, the bare repository exists primarily on the server as a centralized version repository. Because no one will modify the code on the server and commit it, this type of repository does not require a workspace. Of course, the way it is created is slightly different from the version library with the workspace.

$ git init--bare

Option--bare is used to create a bare repository, open the current directory and you will see git creating some directories and files.

For easy viewing, the directory name of the bare repository is usually added to the. git suffix:

$ git init–bare hello.git

This is a lot clearer, both in terms of appearance and use.

initializing a bare version library with an existing library

Because the bare repository does not have a workspace, it is not possible to submit the code directly to the bare version library. The common practice is to clone the bare repository, commit it in the local library, and then push it to the bare repository.

So how do you initialize a bare repository with an existing library?

All roads lead to Rome, and we can achieve it in different ways.

Method 1, clone a bare repository from an existing library:

$ git clone–bare Hello Hellobare.git

Use the git log command to view the repository Hellobare.git, whose history and repository Hello are the same.

Method 2, push the existing library to the bare repository:

$ git push–all hellobare2.git

Using the git log command to view the Hellobare2.git library, its history and repository Hello are the same.

Git Initialize Repository

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.