Learn: Use git to add SSH keys to GitHub

Source: Internet
Author: User

First, register for GitHub and follow the guide to learn basic github operations, such as creating a warehouse named codes.

Second, install Git

Git is easy to use:

1) git initialization configuration (adding usernames such as hahaha and mailboxes such as hahaha.163.com, is not equivalent to a GitHub account, just equivalent to leaving contact information):

# git config--global user.name hahaha

# git config--global user.email hahaha.163.com

2) Create an empty directory first, such as MyProject to the directory, and then use the command to turn the directory into Git's local repository:

# git Init

At this point, there will be one more. Git hidden directory under the MyProject directory.

3) clone the Codes repository locally:

On GitHub, open the Codes repository and click "Clone and Download" to copy the URL.

Use command # in MyProject directory # git clone < just copied url>

After that, you can see that there is a codes directory in MyProject, which indicates the success of the Clone repository. In the same way, you can clone someone else's project.

4) Assuming that the test.c is created in the local codes directory at this point, put it on GitHub

You can enter # git add codes/ in the MyProject directory

or enter # git add test.c in the codes directory

5) using the # git commit command, you will be prompted to enter a comment, or you can use the # git commit-m "add test.c" to submit a comment at the same time.

Then use the # git push command to submit it to GitHub's repository, which will prompt you to enter your GitHub account and password. You can then see the test.c file in the GitHub repository.

Third, in the Add SSH (already installed) key to GitHub, the following steps:

1) terminal Input # ssh-keygen-t rsa-c "[email protected]" command to create a new key, prompted to enter the path can be directly to the default, then prompted to enter the SSH key used by self-setting.

Successful key generation will show the location of the public key, the default is: Your publicly key has been saved In/home/user/.ssh/id_rsa.pub

2) Use the Cat command to view the id_rsa.pub file and copy all of the displayed content completely.

Open GitHub user settings and create a new SSH key. Paste the public key you just copied in the key area, and add the title to complete the addition.

3) Use # ssh-t [email protected] to test if SSH is enabled successfully.

4) using # git remote-v to view the URL of the remote repository, select Use SSH in the GitHub repository clone and download, and copy the URL.

Use the # git remote Set-url origin < copy url> command to use the SSH URL instead. Use # git remote-v to see if there are any successful changes. If the remote repository URL is no longer the HTTP start, the description succeeds. If you push again, you no longer need to enter your GitHub account password.

Learn: Use git to add SSH keys to GitHub

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.