Feynman skills to learn GitHub (2)

Use GitHub

1. Register an account
Enter the GitHub official website and register. The process is simpler than registering for QQ, so I won't say much.
2. Configure GitHub (settings in Linux environment)

  • Log in to your new account and click on the avatar, a drop-down menu will appear, click Settings, find Emails, and add the email address used by your local computer and GitHub to communicate.
  • Go back to the local to create the ssh key
$ssh-keygen -t rsa -C "你刚才在GitHub账号里添加的邮箱"

After that, you will be asked to write the path where the key is stored and the password to generate the key. Because it's not a secret, just hit Enter all the way here, just use the default value. If successful, the public and private keys will be ~/.sshgenerated in the folder .id_rsa.pubid_rsa

  • Open id_rsa.puband copy all the content inside, then open your GitHub account, click Settings, find SSH keys and GPG keys, click new SSH key, write the title as you like, and paste the public key you just copied in the sidebar of the key.
  • determine whether it is successful
$ssh -T git@github.com

The first input may prompt whether you want to continue (the reason is .sshthat there is no file in your folder know_host). Enter yes, and a file will be automatically .sshgenerated in the know_hostfile

  • Configure your git with your username and email address, because GitHub needs to record, so others know the information of the commit person (I guess it can be different from the GitHub account information)
$git config --global user.name "你的用户名"
$git config --global user.email "你的邮箱地址"  
//--global 是把其设置为全局量

( The difference between adding global and not adding global )
3. Linking local and GitHub

  • Uploading local content to GitHub
    Before doing this you need to understand the GitHub workflow. write picture description here
    Your local repository is composed of three "trees" maintained by git. The first is yours 工作目录, which actually holds the file; the second 暂存区(Index), it acts like a cache area that temporarily holds your changes; and finally HEAD, it points to the result of your last commit. For example: You are modifying the word document sent by the teacher. The original document is the working directory, your changes are the cache area, and after you click save, it is the HEAD.
    So you want to upload a local file to GitHub, first you have to add the file to the cache:
git add <filename>
git add * //添加当前目录下的所有文件

then commit the changes toHEAD

git commit -m "代码提交信息"

If your local repository is not associated with a remote server, you need to do it (you have to tell git where to push the repository)

$git remote add origin git@github.com:yourName/yourRepo.git

Finally push your code to the branch you want to push to

$ git push origin master//这里推送到的是 master主分支上

Well, now you have completed the work related to pushing the local code to GitHub.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324501463&siteId=291194637