在GitHub上新建一个bookstore仓库,然后初始化后,仓库中只存在README.MD文件。
在本地新建Git仓库:
1、mkdir bookstore
2、cd bookstore
3、git init
4、将文件添加进去(file)
5、git add file1 file2 file...
6、git commit -m "add files"
7、git remote add origin [email protected]:hahaha/project.git
8、git push -u origin master
在这里,出现了错误提示:
error: failed to push some refs to ‘[email protected]:michaelliao/learngit.git‘
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. ‘git pull‘)
hint: before pushing again.
hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.
这里提示推送失败,因为在GitHub上初始化了一个README.MD文件,远程仓库中的文件比本地的要新,所以要使用git pull要把最新的文件抓下来,与本地的文件合并之后在提交。
9、git pull
提示错误:
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), done.
From github.com:michaelliao/learngit
fc38031..291bea8 dev -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
原因是没有指定本地master和远程origin/master的连接。
10、设置连接
$ git branch --set-upstream master origin/master
11、git pull
12、然后提交
git commit -m "merge README.MD"
13、git push -u origin master
完成本地上传远程仓库。