Git configuration learning notes under Ubuntu

Source: Internet
Author: User
Although svn has been obtained before, the boss recently asked to use git for version control. Okay, pause the projects on hand, and try Git. The learning material is the ebook of progit, which is very detailed. We strongly recommend that you move to progit to learn more. You can select a Chinese version at the bottom of the ebook. Because it was a project developed by several people, git was configured for a private small team. Private means that everyone has read and write permissions and is not made public. So SSH public key is used

Although svn has been obtained before, the boss recently asked to use git for version control. Okay, pause the projects on hand, and try Git.

The learning material is the ebook of progit, which is very detailed. We strongly recommend that you move to progit to learn more. You can select a Chinese version at the bottom of the ebook.

Because it was a project developed by several people, git was configured for a private small team. Private means that everyone has read and write permissions and is not made public. Therefore, the SSH public key is used for authorization.

Assume that there are three persons in the project:

Ritter ip: 192.168.1.1, tom ip: 192.168.1.2, jack ip: 192.168.1.3. The ritter Server is a git server.

First, each person obtains their own ssh public key, and each person installs ssh first:

$ Sudo apt-get install openssh-client

$ Sudo apt-get install openssh-server


Then run the ssh-keygen command to generate the ssh public key:

$ Ssh-keygen


After entering the command, you may need to enter some configuration information. If you do not want to enter the configuration information, press enter to the end.

Now, in ~ /. There should be a file named id_rsa.pub In the ssh directory. Open it with gedit:

$ Gedit ~ /. Ssh/id_rsa.pub

Copy the content in id_rsa.pub to ritter's ~ The/. ssh/authorized_keys file contains the content of ritter in id_rsa.pub.

If ~ /. There is no authorized_keys file in the ssh directory. You can use gedit to create a new one:

$ Gedit ~ /. Ssh/authorized_keys

Then, paste the content in id_rsa.pub of each person into the file. In this way, you have configured the ssh Public Key. users who have a public key in authorized_keys can read and write to the git repository.

The following is the git repository for ritter configuration. If you create a project. git in the/work directory:

$ Sudo mkdir/work

$ Cd/work

$ Mkdir project. git

$ Cd project. git

After entering the project. git directory, you can run git init with the -- bare option to create a bare repository, which will initialize a repository that does not contain the working directory:

$ Git -- bare init

This is. A message is displayed, indicating that the initialization is complete. Then, the file is added to the bare repository.


Assume that tom adds a project named myProject to the repository. First, enter myProject:

$ Cd myProject

Use the git init command to change the project to the git version control directory:

$ Git init

After successful execution, you can run the ls-a command to view the hidden. git Directory, which stores version control information.

Then execute git add.. Note that after adding, there is a space and a dot. This command adds all the files in the current directory to the temporary storage area:

$ Git add.

In this case, you also need to add commit. After adding the Parameter m, you can add comments:

$ Git commit-m' initail commit'

Now the local snapshot is updated and sent to the git server of ritter:

$ Git remote add origin ritter@192.168.1.1:/work/project. git

Here, the origin is the name of the branch in the git repository that you have customized. Then, click "push" and the change is successful:

$ Git push origin master

The origin is the name of the branch in the git server of the ritter machine just named, while the master is the name of the branch of the local storage, which is the default name generated after git init.

The above command is to apply the modifications in the master of the local branch to the origin branch of the git server of ritter. Now, the git server code repository has been configured.

Next, if jack wants to participate in development, clone the code from ritter. If jack wants to clone the code ~ In/jackProject, first enter the jackProject directory:

$ Cd ~ /JackProject

Then run the clone command:

$ Git clone ritter@192.168.1.1:/work/project. git

After the execution is complete, the myProject uploaded by tom in the ritter is downloaded to jack's jackProject directory. Of course, you can add a custom folder name after the clone command,

Assume that you want to rename the project:

$ Git clone ritter@192.168.1.1:/work/project. git project


In this way, you can.

If ritter is also involved in development, it can also be cloned to its own development directory, with the same method.

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.