简介
本文简述通过git上传文件和迭代的过程(以上传至github为例)。
git官网:git
首次上传
在待上传文件的文件夹内右键选择“Git Bash Here”。
在git窗口中依次输入以下内容:
git init
git add .
git commit -m "注释"
git branch -M main
git remote add origin https://github.com/xxx/yyy.git
git push -u origin main
注意:
- “git init”会在文件夹中生成.git文件夹(隐藏的文件夹)。
- “git add .”中“.”代表添加所有文件。
- “git commit -m”提供快速编辑commit,省略“-m”进入vim。
- “https://github.com/xxx/yyy.git”中“xxx”为github中的用户名,yyy为repository名。可以在创建repository后点击右侧按钮复制HTTPS。
更新提交
在git窗口中依次输入以下内容:
git status
git add .
git commit -m "注释"
git remote -v
git push
可能出现的问题
- 第一次使用git
第一次使用git时可能需要配置用户名和邮箱。
参考:git配置用户信息
- Updates were rejected because the remote contains work that you do hint
原因:在github上修改文件,导致和本地文件冲突。
解决方法:github遇到问题Updates were rejected because the remote contains work that you do hint: not have locally.