1. Create a github account
First check if a key has been generated ~ cd / .ssh, LS if there are three files, the key has been generated, id_rsa.pub is the public key
You can also open My Computer C: \ Users \ 17500 \ .ssh found inside
If not generated, it is generated by $ ssh-keygen -t rsa -C "[email protected]".
3.2 Configuring ssh key to github account
Switch to github, expand the small triangular profile picture, click on settings
Then open SSH keys menu, click Add SSH key new key, fill in the title, consistent with the warehouse it, a good distinction.
Then paste them into this key file id_rsa.pub, and finally generate the key Add key bar.
So, github account SSH keys configured.
4. Upload local project to github
4.1 Creating a local project
I This creates several empty folder and a file and a project profile, so take a lot of front-end architecture projects
4.2 local repository
git init
Upon successful initialization of the project you will find one more hidden folder .git
This directory is used to track and manage Git repository, all right, do not manually modify the file or folder, or change the mess, put the Git repository to destroy.
Next, add all the files to the repository
Executes instructions: git the Add.
Then, the submission of documents to the repository, the comment is submitted within double quotes.
Executes instructions: git the commit -m "submission"
So the establishment of good local warehouse.
4.3 associated github repository
Copy the address of the warehouse to warehouse github beautifulDay
然后执行指令:git remote add origin [email protected]:wangjiax9/beautifulDay.git
其中,遇到【git 端口拒绝解决方案】ssh: connect to host github.com port 22: Connection refused
github端配置完毕后,看本地的git 如何添加远程仓库,以下是重头戏:
第一步,查看当前git的远程仓库版本:
$ git remote -v
此时若什么都没有显示说明,git无远程仓库。
第二步,添加ssh协议的远程仓库:
$ git remote add origin git@github.com:unlimitbladeworks/Data-Struts-Learning.git
再次查看
- $ git remote -v
- origin [email protected]:unlimitbladeworks/Data-Struts-Learning.git (fetch)
- origin [email protected]:unlimitbladeworks/Data-Struts-Learning.git (push)
当前,我本机就是用的这种方式连接的github,好处是每次提交代码时,不需要重复来回输入用户名和密码。
报出如下错误:
4-4 上传本地代码
执行指令:git push -u origin master (第一次的时候),之后就用 $git push origin master(只要本地做了提交,就可以使用这个命令)
1)敲一个:yes, 然后回车
到此,本地代码已经推送到github仓库了,我们现在去githubt仓库看看。
咦!奇怪了,我的目录呢?这个坑突然冒出来是不是印象很深刻呢~
注意咯:git是不能管理空的文件夹的,文件夹里必须有文件才能add
好,我们来试一下,我在examples里新建了一个test1.html文件
执行指令添加文件->提交文件->推送文件
git add .
git commit -m "提交test1.html"
git push -u origin master
然后刷新一个github,你会看到,examples文件夹出来了。
打开examples文件夹,test1.html也在里面。