- 上传本地项目到GitHub
mkdir demo
cd demo
echo "# demo" >> README.md
git init //把这个目录变成Git可以管理的仓库
git add README.md //文件添加到仓库
git add . //不但可以跟单一文件,还可以跟通配符,更可以跟目录。一个点就把当前目录下所有未追踪的文件全部add了(空目录不会被添加)
git status //查看当前工作区的状态(需提交的变更)
git commit -m "first commit" //把文件提交到仓库
git remote add origin git@github.com:hxf0663/demo.git //关联远程仓库
git push -u origin master //将本地主分支推到远程(如无远程主分支则创建,用于初始化远程仓库,第一次用,后面只用下面的即可)
git push origin master //将本地主分支推到远程主分支
- 克隆远程仓库到本地
git clone git@github.com:hxf0663/demo.git
- 更新远程仓库到本地(并覆盖本地)
git pull origin master
- git清空缓存
git rm -r --cached .
- .git文件太大
直接重建
rm -rf .git
git init
git add -A
git commit
- git提交到远程仓库冲突
error: failed to push some refs to 'https://github.com/GDDXZ/RobotDenso.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.
- 强制推送
git push -f
可以提交,会将remote上第一个人的改动冲掉,比较暴力,不太好。
- 正常解决
先 git fetch origin 然后git merge origin/master, 和本地分支合并, 之后再push。