How to upload your local code to GitHub

Source: Internet
Author: User
Tags commit ssh git client using git
How to upload your local code to GitHub

Description: Win7 operating system, the client uses Git. Preface

When searching for information, I saw a lot of friends who put the source code on GitHub, so I had the idea of uploading my codes to GitHub. This article for beginners, hands-on teaching you to complete the task. 1. Register your GitHub account

Register your GitHub account with https://github.com. Then log in and authenticate with the mailbox. 2. Build a warehouse on GitHub (1) Click the "New Repository" button on the right to create a new warehouse.

(2) After filling in the name (oneself from one), click "Create repository"; note Do not tick initialize this repository with a README.

(3) Find the address of the warehouse

After the above work is completed, a prompt page will appear to find the contents of the box below, which is your warehouse address. We'll use it in the following article.
3. Download and install the GIT client

Go to Http://git-scm.com/downloads to download and install the GIT version management tool, which is a client. 4. Configure user name and email address (1) On the Start menu, open git Bash

(2) Configure user name and email address

We need to set up a username and a mailbox, and when the local repository is uploaded to GitHub, the code uploader will appear on GitHub.

Enter the following command in Git bash. Assuming the username is Tom, the email address is TomWhite@163.com

git config--global user.name "Tom"
git config--global user.email "TomWhite@163.com"
5. Generate SSH keys

Note: Please use the email address registered with your GitHub account when using this command.
Enter the following command

Ssh-keygen-t rsa-c "Hello@163.com"

3 consecutive carriage returns (if no password is required). Finally, two files were obtained: Private key id_rsa and public key id_rsa.pub. 6. Add encryption key to Ssh-agent

Ssh-agent is equivalent to a key manager that, after running Ssh-agent, uses the Ssh-add command to give the private key to ssh-agent for safekeeping.

Eval "$ (ssh-agent-s)"

And then

Ssh-add ~/.ssh/id_rsa
7. Login to GitHub and add SSH public key (1) in the top right, find "Settings", then click "SSH and GPG Keys"

(2) Click "New SSH Key" in the upper right corner. (3) title himself as a (4) Copy and paste the contents of the Id_rsa.pub file

Locate the Local. SSH folder, open the Id_rsa.pub file with the Notepad program and copy the contents of the file and paste it into that box. Finally click on "Add SSH Key"

8. Test if the public key is added successfully

Enter a command in Git bash

Ssh-t git@github.com

Then enter Yes, and if you see that your username is behind the hi, that means it's successful. Similar to the following figure.

9. Create a local repository and upload the code to GitHub

Find yourself sharing the uploaded code folder, right-click Git bash, or go to this folder in Git bash.

(1) initializing the local repository

Git init    

This command creates a. git folder in the current directory. (2) Select the files to add to the local warehouse

git Add.

This command adds all the files under the current path to a list.
If you do not want to add all the files, just want to add the specified, just put "." Change to a file name. (3) Submit file to local repository

Git commit-m ' first commit '

-M followed by a parameter indicating that after submitting the code to GitHub, the description will be displayed on the code file information, as shown below.
Note: Each time git commits the code, it writes a commit message (the commit), otherwise it is not allowed to commit.

(4) Adding a remote host

Git remote add Origin git@github.com:xxx/xxx.git

This git@github.com:xxx/xxx.git is the address that was created before the warehouse, and the address of the remote host; Origin is the remote host name. (5) uploading the local repository to GitHub

Git push-u Origin Master

The above command pushes the local master branch to the origin host, specifying origin as the default host, and then using git push without any parameters.

So far, your code has been shown on GitHub. Take a look at it:)

Pasting a picture below (from reference [3]) is very helpful for us to understand how git is used.

References

[1]git-ssh Configuration and use
[2] using git to upload native code to GitHub
[3] Git remote operation detailed

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.