将github上的仓库和本地仓库关联:
$ git remote add origin git@github.com:github账户名/learngit.git |
$ git push -u origin master |
后面直接使用:
$ git push origin master |
我后面修改使用此命令时,出现了如下错误提示:
To github.com:zxsmile/learngit.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@github.com:zxsmile/learngit.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
从提示语中可以看出是,问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。
我在看了别人博客之后有了如下解决方案:
首先从远程的origin的master主分支下载最新的版本到origin/master分支上 :
git fetch origin |
git merge origin/master |
git add <文件名> git commit -m "add file" git push origin master |