git操作
每次建立新的仓库,提交的时总会出现这样的错误,真是头疼,......
直接开始正题,git 提交的步骤:
-
git init //初始化仓库
-
git add .(文件name) //添加文件到本地仓库
-
git commit -m "first commit" //添加文件描述信息
-
git remote add origin + 远程仓库地址 //链接远程仓库,创建主分支
-
git push -u origin master //把本地仓库的文件推送到远程仓库
提交之后就会出现以下错误
要想解决以上错误,只需要在4,5之间使用git pull origin master即可
正确步骤:
-
git init //初始化仓库
-
git add .(文件name) //添加文件到本地仓库
-
git commit -m "first commit" //添加文件描述信息
-
git remote add origin + 远程仓库地址 //链接远程仓库,创建主分支
-
git pull origin master // 把本地仓库的变化连接到远程仓库主分支
-
git push -u origin master //把本地仓库的文件推送到远程仓库
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
经百度后,得知‘matching’ 参数是 Git 1.x 的默认行为,其意是如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支。而 Git 2.x 默认的是 simple,意味着执行 git push 没有指定分支时,只有当前分支会被 push 到你使用 git pull 获取的代码。
根据提示,修改git push的行为: