web操作:
- 首先去网站新建GitHub仓库。
本地操作:
- 进入到要建仓库的目录
- git init。
- it remote add origin git@github.com:RayHauton/***.git
- git push -u origin master ------><font color='red'>此时可能会有问题</font>
如果在网站中新建仓库的时候新添了README文件的时候,此时push不上去,会报如下错误:
$ git push --set-upstream origin master
To github_second:RayHauton/ScheduleManagerApp.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github_second:RayHauton/ScheduleManagerApp.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 pull --rebase origin master
此时本地方会多出README文件。然后可以进行
git push -u origin master
的操作。此时就成功了
push完毕之后,新建分支并且关联到远程分支的时候依然会有问题,表现如下:
如果远程还有一个dev分支,如果在本地git checkout -b dev新建dev以后,然后直接关联
git --set-upstream-to origin/dev
会报错,如下:
error: the requested upstream branch 'origin' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
根据错误中的提示运行:
git fetch
然后在进行关联就行了。