在命令行中输入:
echo "# text" >>README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/CrazyDony/text.git
git push -u origin master
会出现以下错误
error: failed to push some refs to 'https://github.com/CrazyDony/text.git'
hint: Updates were rejected because the remote contains work that you dohint: 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.
出现错误的主要原因是github中的README.md文件不在本地代码目录中,
命令行中输入:
git pull--rebase origin master
git push -u origin master
然后又会出现
error: failed to push some refs to 'https://github.com/CrazyDony/text.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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 origin master
出现
failed to push some refs to 'https://github.com/CrazyDony/text.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.
原因:自己分支版本低于主版本
git push -u origin master-f
Counting objects: 35, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (35/35), 10.15 KiB | 0 bytes/s, done.
Total 35 (delta 5), reused 0 (delta 0)
To https://github.com/CrazyDony/text.git
+ aa70966...f64b22a master -> master (forced update)
Branch master set up to track remote branch master from origin. 完成.