Github website introduction, and use git commands to manage github (detailed description), githubgit

Source: Internet
Author: User
Tags git commands

Github website introduction, and use git commands to manage github (detailed description), githubgit

Learn this chapter:

  • 1)Familiar with github website
  • 2)Remotely manage github using git commands,
  • 3)You do not need to enter the account and password to use the ssh key for git commands.

 

 1. First, familiarize yourself with the github website.

1.1 register github

Log on to http://github.com/and click sign up to register an account:

 

After registering and verifying the email address, go to the github homepage:

 

1.2 Click start a project (start the first project)

 

1.3 after the project is created, the page of the created test2 warehouse (project) is displayed, as shown in the following two figures.

  • Figure 1:

 

  • Figure 2:

 

Let's first introduce several frequently used words.

  • Repostory

A warehouse, that is, a project. Multiple projects represent multiple warehouses.

  • Star

The more items you add to favorites, the better the project.

  • Fork

Clone the source author's project to your project.

  • Pull request

Pull request, such as the pull request.

For example, after someone passes fork on your project and improves the project, they send you a new pull request,

Then you click the pull request button. After Entering, it will appear, as shown in:

Click Merge pull request to Merge the improved content to your project,

  • Watch

Focus on projects. When you update a repository, you will be notified on your github homepage.

  • Lssues

Click here to view the questions raised by everyone, such as bugs in the project.

When you want to publish a question, click "lssues-> new lssues", as shown in:

1.4 next, click create new file on the repository homepage to create a file:

 

After submission, we will return to the homepage of our test2 Repository:

 

Click commits submit to view the details of the created main. c:

 

PS: When an error is deleted, you can use the commits button to find the previously deleted file.

1.5 learn how to change the repository name and delete a repository

On the repository homepage, click settings, as shown in (taking test3 as an example ):

 

Then, the next interface is displayed, and the repository name can be changed:

 

Continue to the next step to delete the Repository:

 

2. Use git to manage github

2.1 install git

: Https://www.git-scm.com/download/win

(If it is slow, go to http://www.wmzhe.com/soft-38801.html to download it)

After the download is complete, install it by default. If you only like the command line mode, cancel git gui here on the Component Interface, as shown in:

 

After installation, as shown in, you can use the linux Command to operate the git command:

 

If you install git on linux, enter:

apt-get install git

 

2.2 configure git

Git config -- global user. name "lifeyx" // personal account git config -- global user. email 123456@qq.com // personal email address

 

The -- global option above indicates that the above user information is used by default for future git library management. You can also view the configuration information through git config-l.

2.3 git command Introduction

1) Before the introduction, you should first understand the three regions of git, as shown in

 

The git repository of is a local repository and will not be updated to a remote repository (the repository on the github page). You need to use the git push-u origin master command.

2) then explain the common git commands.

git init   

Perform git management on the current directory, and the Directory becomes the work zone. A. git hidden directory appears under the current directory.

The. git stores the data and resources required by git, that is, the git repository and the staging area are saved in. git.

 

git clone https://github.com/lifeyx/test2.git

Clone and copy the remote repository to the current directory and generate the test2 folder. The. git directory is automatically created and the remote repository information is saved.

The remote repository address is obtained in the red box:

 

 

git status

Check the file status in the working directory and whether to add the file to the temporary storage area. For example:

 

 

 

git add file

Add the files in the workspace to the temporary storage area.

 

git rm file 

Delete the files in the temporary storage area. If the workspace file exists, use git rm-f file to forcibly delete the files.

 

Git commit-m "Submit description"

Submit the files in the saved area to the local warehouse. If a file in the saved area is deleted, the files in the saved area are deleted.

 

Git commit-am "submit description"

-A: Skip the temporary storage area. git automatically adds all files recorded in the workspace to the temporary storage area and submits them together to skip the git add step.

 

git remote add origin https://github.com/lifeyx/test3.git

Add a remote repository (origin), that is, associate the local repository with the github repository. The remote repository address is obtained in the red box:

 

 

git push -u origin master

Push (synchronize) data to a remote warehouse. If the data is uploaded locally, you must use the previous command to specify the remote warehouse address (origin ),

If it is cloned and copied from a remote repository, it is not required because the remote repository address is automatically saved in. git.

2.4 git remote repository management-instance 1

Step 1: Create a remote warehouse and then push (synchronize) local data to the remote warehouse.

1) create a remote repository first. Take test3 as an example.

 

Then find the remote repository address: https://github.com/lifeyx/test3.git

 

2) Go To The github command line and enter

Mkdir test3cd test3echo "project description test3"> README. md git init // initialize gitvi 1.txt // create 1.txt git add README. md // Add README. md git add 1.txt // commit 1.txt git commit-m "Submit file for the first time" // submit to local repository git remote add origin https://github.com/lifeyx/test3.git // connect to remote repository address git push-u origin master/ /upload to the remote repository address, and enter the account password

3) view results

 

 

2.5 git remote repository management-instance 2

Step 2 of instance 2 is to download the remote warehouse to the local through cloning, modify the data locally, and push (synchronize) the data to the remote warehouse.

1) The previous remote repository test2 is used as an example.

As shown in, we can see that the update time of the test2 repository is one day ago:

 

Then through the green button, find test2 address: https://github.com/lifeyx/test2.git

2) Go To The github command line and enter

Git clone https://github.com/lifeyx/test2.git // download test2 repository cd test2 // enter repository vi 1.txt // create 1.txt git add 1.txt // submit 1.txt git commit-m "Submit file the next day" // submit to local repository git push-u origin master // upload to remote repository address, and enter the account password

PS:

Because git clone will automatically generate a. git hidden directory, the above does not require git init command initialization.

In addition, the remote repository address is saved in the. git directory, so you do not need to use the git remote Command to connect to the remote end.

3) view results

 

 

3. Every time I upload a file to a remote warehouse address, I have to enter the account and password. Is it very troublesome?

Next, connect the host to the server through the ssh key, so that you do not need to enter the account password each time.

3.1 generate an ssh key

First, use ls ~ /. Ssh command to check whether there is an ssh key. If there is an ssh key, back up the key first, and then use rm-rf ~ /. Ssh to delete

1) enter and create a key

Enter the mailbox number in ssh-keygen-t rsa-C "123456@qq.com "// "..."

2) then, the system will prompt you to set the password. Press 3 and press enter to indicate that the password is empty.

3) Add the new key to the ssh-agent.

eval  "ssh-agent -s"ssh-add ~/.ssh/id_rsa

4) if "cocould not open a connection to your authentication agent." is displayed, enter

ssh-agent bashssh-add ~/.ssh/id_rsa

As shown in, the "Identity added" field indicates that the write is successful, and the ssh key public key is saved in the id_rsa.pub file:

 

5) then use cat ~ /. Ssh/id_rsa.pub print out the ssh key public key and copy

 

3.2 Add the copied ssh key public key to github

 

After you jump to the page, enter the title at will. Copy the ssh key to the key box.

3.3 test the ssh key

Enter the ssh git@github.com, as shown in, to display Hi youname! , Indicates that the operation is successful.

 

 

After 3.4 is successful, you can use the git protocol to download the repository. Take the test2 repository as an example.

1) First, check the ssh protocol address of the test2 repository (previously the http protocol address)

 

As shown in, click the red box and change the prefix https: // to git @

2) then go to the github command line to test

Git clone git@github.com: lifeyx/test2.git // download the test2 repository cd test2 // enter the repository vi 2.txt // create 2.txt git add 2.txt // export 2.txt git commit-m "Submit file the next day" // submit it to your local repository git push origin master // you do not need to enter a password to upload

 

The test is successful and you will not need to enter the password in the future. Thank you for reading ~

 

 

 

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.