Create a library locally with the command line and upload it to GitHub

Source: Internet
Author: User

1 How do I create a repository locally and upload it to GitHub?

  • Basic steps:
    $mkdirBlog//Create a directory called "blog" on the desktop$ CD Blog//"CD blog" Into the directory$ git init//git init creates a repository in the Directory "blog" (using "Ls-la" to view)Initialized Empty Git Repositoryinch/users/nola/desktop/blog/.git/$ TouchIndex.html//"Touch index.html" creates a file called "index.html" in the Directory "blog "$ git STATUS-SB//"Git status-sb" is used to view the file changes as follows "?? "Means there is a change, asking you how to deal with the change# # No commits yet on master??index.html$ git add index.html//"git add index.html" adds the new "index.html" file to the staging area$ git STATUS-SB//"Git status-sb" again to see the changes in the file, the green "A" means adding a new file to the warehouse# # No commits yet on Mastera index.html$ git commit-M"my first time to submit"     //"Git commit-m" formally submits the file of the staging area to the local repository, which is the ". Git" repository created in the third step\[master (root-commit) be29eb7\] My first time to submit1 fileChanged0Insertions (+),0Deletions (-)//Create mode 100644 index.html$ git pull//download GitHub's update to local$ git push//Upload to GitHubPS: If add mistakenly wants to undo the contents of the Add, you can use"git reset HEAD file name"If add is wrong and commit, you can use"Reset--hard head^";

2 How to get an SSH key

  • Why do I need to get SSH key? -Because SSH key allows access to all of your warehouses.
  • How many SSH keys does a computer need? -Each computer needs only one.
  • How do I get ssh key? --refer to the following steps:
    *To get the SSH key step:*sign in to GitHub*Click the avatar in the top right corner of the page*select Setting*Select SSH and GPG keys*Click Generating SSH keys* Click Generating a new SSH key and adding it to thessh-agent* Copy the first black command of generating a new SSH key"ssh-keygen-t rsa-b 4096-c"[Email protected]""to Gitbash (or terminal)*enter three times and then get a bubble-like thing that means it 's done.* then enter"Cat ~/.ssh/id_rsa.pub", get a bunch of English, copy this paragraph of English* Go back to the 4th step of the page and click on the green button in the top right corner"New SSH Key"*put what you just copied into the text box below the key, edit a title casually, click the green button below to confirm the addition* Back to Git Bash (terminal), run"ssh-t [email protected]"Test is successful, get a hint to get you back to yes/No, enter Yes to return* If you get"Permission denied (publickey)", unfortunately, you have failed and need to start again from the first step;"You ' ve successfully authenticated", then congratulations, you made it.
  • Tips: If you already have SSH key and need to be re-added, you can run "Rm-rf ~/.ssh/*" in Git Bash before doing the above steps to delete the existing SSH key
  • The pits that have been trampled:
    * in"ssh-t [email protected]"When you encounter code such as the opening parenthesis, in general, enter"Ping github.com"can be resolved. (Error prompt:SSH: Could not resolvehostname[Github.com] (http://github.com): NodeName nor servname provided, or not known)

    * Input"git remote add origin [email protected]:nolaaaaa/yyy.git"When you encounter code such as the opening parenthesis, enter"git remote rm Origin"And then re-press the steps to lose"git remote add origin [email protected]:nolaaaaa/yyy.git""git push-u Origin master"can be. (Error Hint: Fatal:remote origin already exists.)

Create a library locally with the command line and upload it 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.