banner
阿珏酱

阿珏酱

乘上与平常相反的电车,去看看那未曾见过的风景
twitter
github
facebook
bilibili
zhihu
steam_profiles
youtube

Simple steps for using Git

Tips: When you see this prompt, it means that the current article has been migrated from the original emlog blog system. The publication time of the article is too long ago, and the formatting and content may not be complete. Please understand.

Simple steps to use Git

Date: 2018-4-3 Author: Ajue Views: 2117 Comments: 0

This article does not explain any conceptual knowledge, it is just a note, a simple usage steps. If you encounter any obstacles, please Google it.

Use SSH to bind Git and GitHub#

  1. Generate

SSH key

ssh-keygen -t rsa

Specify the RSA algorithm to generate the key. After that, two files will be generated, id_rsa and id_rsa.pub, which are the private key and public key respectively. For these two files,

  1. Add SSH key
github.com -> Settings -> SSH and GPG -> New SSH key Paste the content of the public key id_rsa.pub into the Key field (the Title field can be left blank), and then click Add SSH key.
  1. Verify if the binding is successful

Commands to push local projects to GitHub#

(1) Open your directory

cd demo 

(2) Initialize the repository to generate git files

git init

(3) Add all files to the staging area

git add * 

(4) Commit the changes in the current workspace

git commit -m "first commit"

(5) Connect the repository to the remote server

git remote add origin <server>(the address of your repository) 

(6) Push the changes to the added server

git push -u origin master 

If you encounter the following error when pushing:#

warning: redirecting to https://github.com/178146582/dabai.git/
To http://github.com/178146582/dabai.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://github.com/178146582/dabai.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

After checking, the reason for the error is that the README.md file in GitHub is not in the local code directory. So we split the sixth step into two steps:

git pull --rebase origin master: perform code merging 
git push -u origin master 
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.