第一步:在 github 中添加密钥
生成本地密钥:
- $ ssh-keygen -t rsa -C ""
命令执行后会提示生成的. ssh 文件夹的位置,进入打开 id_rsa.pub 文件,复制里面的所有内容。
添加密钥:
回到 github,个人头像下进入 Settings,再进入 SSH,new ssh key,填写 title,粘贴复制的密钥。
第二步:本地项目上传:
1. 在 Project 根目录下执行 git init,把工程转化成 git 工程(工程中增加了. git 文件夹)。
2. 在 Project 根目录下配置提交的用户名和 mail 地址:
- git config --global user.name "yourname"
- git config --global user.email ""
3. 在 Project 根目录下执行 (在 github 上新建 new repository,名为 Project):
- git remote add origin https: //github.com/yourname/Project.git
执行完该命令后,.git/config 文件下增加如下内容:
- [remote "origin"] url = https: //github.com/yourname/Project.git
- fetch = +refs / heads
- /*:refs/remotes/origin/*
- */
4. 执行提交流程:
- git add .
- git commit -m "first commit"
- git push origin master (第一次需要加参数,后续直接git push即可)
执行后. git/config 文件增加如下内容:
- [branch "master"]
- remote = origin
- merge = refs/heads/master
完成上传
来源: http://www.bubuko.com/infodetail-1992688.html