"Linux Learning Notes" show Git (ON)

Source: Internet
Author: User
Tags version control system git clone

This article is for "Liaoche git Tutorial" Learning notes, the original address:

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000


Meng new introduction, a little experience, the play said.

This chapter consists of two parts:

1. Adding and submitting files in the Git local repository;

2. Connect GitHub to add a remote library


First, the concept of a genuine town stickers:

Git is currently the world's most advanced distributed version control System (no one).


Assume

I am a stand-alone game enthusiast (well, that's not a hypothesis.) )

Then git can be understood as the archive folder "save"

Your every game progress archive can be understood as the program each different version

Git is responsible for managing these messy archive files.


Installation

In Linux, you can enter git directly to see if the installation

If not installed, it will pop up prompting you to enter:

sudo apt-get install git


To create a repository:

$ mkdir learngit//Create a directory as a repository

$ cd learngit//jump to this directory

$ git init //Initialize the directory with one more. git file in the directory


You can now use the Learngit folder as a repository.

Next, we start writing files to the repository.


In the current directory learngit, create a GGS.txt file with the contents:

Good good study!!


Now that there is one more file in the library, Git realizes that we use the following command to check the status of the current git:

$ git status


The state at this point is understood to be that git realizes that the file in the repository has changed.


There are two steps to follow:


The first step, add, type:

git add GGS.txt

After the carriage return we found no response, no response is the best response, representing the success of Add.

git status Check Status


Here we see that add succeeds and the file name becomes green.


At this point the file entered staging area and was not submitted to the repository.


Step two, Commit, Commit, type:

Git commit-m "Add GGS.txt" //here-M "..." Represents adding version modification comments, which are written in quotation marks to make changes to the current version for easy administration.


Thus, the GGS.txt file is submitted to the library.


Previously mentioned staging area , after the add operation, the file will enter the staging area, can be understood as the queue to be uploaded, I have a batch of modified files waiting for commit, so we put them together, and finally submitted.



Summary

To submit a file to the repository:

Add first, then commit.






So how to synchronize the remote warehouse and the local warehouse?


Next, say, GitHub's survival to usage.


First register your account and go to the Settings page:

Settings---> Personal settings---> SSH and GPG keys---> New SSH key

Title Write a random example my SSH key


Key fill in:

Go back to the Linux home directory and look for the. SSH folder

$ cd/home/recycle //Recycle is the system user name

$ ls-al



If not, create the following:

$ ssh-keygen-t rsa-c "[email protected]" //quotation mark fill in the mailbox

Can not set the password, all the way to enter


This is where you have the. SSH folder, open it with two files in it


These two files are key pairs of SSH key.

Id_rsa is a private key that can't be leaked.

Id_rsa.pub is a public key that can be safely told to anyone


Open the public key id_rsa.pub to copy its contents into the GitHub Web page of my SSH key and confirm the submission.


In this way, the account on GitHub has the key to your local computer, which allows you to freely access and upload data.


Next experiment how to add a remote library


Go to GitHub page


Back to the local warehouse,

$ git Remote add origin [email protected]:wly95/testing.git


Here origin is the name of the remote library and can be changed to other, customary with Origin

Wly95 is my github user name

Testing.git is a newly established repository.


Upload:

$ Git push-u Origin Master


The first time you do this, you'll get an SSH warning, confirm your identity, and type Yes.


Enter the Web page can see, in the testing, with the same as the local warehouse files, upload success.


Download (clone)

$ git clone [email protected]:wly95/testing.git


After that, a testing directory will be located in the current directory, after opening:




Summary of BASIC commands:

$ git init //Initialize git repository

$ git add xxx.xxx //Add file into queue (staging area)

$ git commit-m "xxxxxxx" //Submit current staging area content into the warehouse

$ git remote Add origin [email protected]:username/gitname.git//establish local and Remote Repository Association

$ Git push origin master //local library All content uploaded to remote library

$ git clone [email protected]:username/gitname.git //Download (clone) remote library contents to local

"Linux Learning Notes" show Git (ON)

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.