- 现在Github上新建一个仓库
- 在终端中cd进入要提交的项目
- 命令 touch README.md 创建说明文件
- git init 初始化本地仓库
- git add . 添加所有文件,效果等同于git add -A
- git commit -m '说明' 将文件提交到本地仓库
- 开始连接远程仓库,需要先复制好远程仓库的地址
- git remote add origin '仓库地址' 这里是连接到远程仓库,还没提交呢
- git push -u origin master 把本地的文件通过-u(upStream,上传流) 推送到别名为origin的仓库中的master上
- 这时可能会报错,提示
$ git push -u origin master The authenticity of host 'github.com (192.30.252.122)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,192.30.252.122' (RSA) to the list of known hosts. To git@github.com:gaissiai/learngit.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:gaissiai/learngit.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.
- 是说远程库中的版本比本地的更新,建议你先pull一次.但因为这是我全新建立的一个仓库,所以我决定强制覆盖远程分支,使用了命令 git push origin master -f
- 这里就结束了创建一个仓库的流程
- 以后的修改,大家默认都是如下
- git pull 默认拉取的是master分支的代码
- git add .
- git commit -m '再次修改的说明'
- git push
提交本地项目到github中
最新推荐文章于 2022-05-31 22:01:17 发布