Git basic: Use git to upload native code to GitHub

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

First, create a GitHub repository (warehouse)

1. Login to GitHub

To create a github repository, you first need to login to the Github,github URL: https://github.com. If you don't have a GitHub account, you'll need to sign up for a GitHub account, not here to show you how to sign up for GitHub.

2. Create Repository (warehouse)

There are two ways of creating a repository warehouse.

2.1. Use the downward inverted triangle in the upper right corner to create it, as shown in:

2.2. Create using the new Repository button on the left, as shown in:

3. Start the warehouse creation

Select one of the ways above to create the warehouse, and then go to fill in the warehouse information interface, as shown in:

4. Successful creation

Clicking on the Create Repository button appears as shown in the interface indicating the creation of the warehouse successfully.

Second, install the Git client

GitHub is a server, and if you want to use Git on your own computer, we also need to install a git client.

Git official: http://git-scm.com/download/, download the appropriate version according to your computer's system:

Once you've downloaded git, you'll have to go the next step, using the default configuration. This isn't a demo.

2.1. Bind Git Users

Because Git is a distributed version control system, you need to fill in the username and mailbox as an identity, username and mailbox are github registered account and mailbox. Right-click any folder and open Git Bash, as shown in:

Bind the user name and mailbox in the open Git bash, as shown in:

Attention:

The git config–global parameter, with this parameter, means that all of your git repositories on this machine will use this configuration, and of course you can specify a different user name and mailbox for a warehouse.

Third, set up SSH key for GitHub account

SSH key is known to be encrypted and transmitted. There are many algorithms for encrypting the transmission, and Git uses the RSA algorithm. One of the core issues that RSA solves is how to use a pair of specific numbers so that one of the numbers can be used for encryption, and the other can be used to decrypt the data. These two numbers are the public key that you encounter when you use Git and GitHub, and the private key.

Where the public key is the number that is used for encryption, which is why you upload it to GitHub after you have generated the public key in this machine. From GitHub, the data encrypted with that public key can be restored with your local private key.

If your key is lost, whether it is a public key or a private key, the lost one is useless, the workaround is simple, regenerate again, and then set it again in github.com.

3.1. Generate SSH Key

Use to check if the key has been generated. The CD ~/.SSH represents the entry into the. ssh directory, and LS means to view the files under that directory. If there are 3 files, the key has been generated and id_rsa.pub is the public key.

If no key is generated, you need to create a local SSH key using the following command.

" [email protected] "

The following [email protected] changes to your email address, which is the one registered on GitHub:

Press ENTER after entering the Create path confirmation prompt, directly enter the created SSH key into the default path:

Then the system asks for a password, directly press ENTER to indicate that no password is set:

Repeat the password is also a direct carriage return, after prompting you shh key has been generated successfully.

Then we go to the prompt address to view the SSH key file. Open id_rsa.pub with notepad and get SSH key public key:

3.2. Set SSH key for GitHub account

Switch to GitHub, expand the small triangle of your avatar, and click Settings, as shown in:

Then open the SSH keys menu, click Add SSH key to add the key, as shown in:

Then paste the key in the Id_rsa.pub file to this, and then click the Add Key button to generate the key:

GitHub's SSH Key was created successfully:

To verify that SSH key is added successfully, enter the following command under GIT bash:

$ ssh-t [email protected]

Enter will see: You've successfully authenticated, but GitHub does not provide shell access. This means that you have successfully connected to GitHub.

Iv. uploading local projects to GitHub

4.1. Create a warehouse for a local project

Let's start with a new folder on the computer's hard drive to store the local repository, for example, we've built the local repository under the D:\demo folder. Then go to the folder to do the following

In Git bash, enter the following command:

$ git init

After successful initialization you will find a hidden folder in the project:. Git.

4.2. Add all files to the local repository

Create a new Readme file under the folder and copy the code you want to upload to the directory below:

Then execute the following command to view the currently modified file:

Where the red font represents the modified file.

Execute the following command to commit all new files to the local git cache:

$ git Add.

Attention:

Git Add. Indicates that all files that have been modified are committed.

Execute the command to commit all new files to the Git local repository

" Notes "

4.3. Associated GitHub Warehouse

Then execute the following command:

$ git Remote add origin https://github.com/jiangxiaoliang1988/gitdemo.git

4.4. Upload local code to GitHub remote repository

Get updates to the remote repository before uploading the code:

Then execute the following command to push to the remote server:

$ GIT push origin master

Upload success:

Here, the local code has been pushed to the GitHub repository, so let's go and see GitHub:

You can see that the GitHub remote repository already has uploaded files.

Git basic: Use git to upload native code to GitHub

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.