How to upload your local code to GitHub
Description: Win7 operating system, client adoption Git
.
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, and this 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
Note: Please use the email address registered with your GitHub account.
Enter the following command in Git bash. Assuming the user name is Tom
, the email address is[email protected]
git config --global"Tom"git config --global"[email protected]"
5. Generate SSH Keys
Enter the following command
ssh-keygen-t-C"[email protected]"
3 consecutive carriage returns (if no password is required). Finally, two files were obtained: The private key id_rsa
and the public key id_rsa.pub
.
6. Add encryption key to Ssh-agent
ssh-agent
Equivalent to a key manager that, ssh-agent
after running, uses the ssh-add
command to give the private key to ssh-agent
safekeeping.
eval"$(ssh-agent -s)"
And then
ssh-add ~/.ssh/id_rsa
7. Login to GitHub, add SSH public key (1) and find "Settings" in the top right, then click "SSH and GPG keys"
(2) Click on the "New SSH Key" (3) in the upper right corner to start one (4) copy and paste
id_rsa.pub
The contents of the file
Locate the local .ssh
folder, open the file with the Notepad program id_rsa.pub
and copy the contents of the file and paste it into the 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.
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 folder in the current directory .git
.
(2) Select the files to add to the local warehouse
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
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, such as.
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
add origin [email protected].com:XXX/XXX.git
This [email protected]:XXX/XXX.git
is the address that was generated by the repository, the address of the remote host, and the origin
remote host name.
(5) Uploading the local repository to GitHub
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.
Resources
[1]git-ssh Configuration and use
[2] using git to upload native code to GitHub
[3] Git remote operation detailed
How to upload your local code to GitHub