当需要将本地的已有的项目作为工作区,并新建本地库来跟踪工作区的变化,同时需要将本地库推送到分布式的服务器上(如:github)上时,需要进行以下操作:

  • 右击本地文件夹,git bash here
  • 建立本地库
    在弹出的命令行中输入git init
  • 在github上新建库,命名为projectA
  • 将本地库和github上面的远程库关联
    git remote add origin git@github.com:username\projectA
  • 将本地库的内容推送到github上
    git push -u origin master

在最后一步,将本地库的内容推送到github上时报错,内容为:

error: src refspec master does not match any.
error: failed to push some refs to 'ssh://xxxxx.com/project.git'

解决方案:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.

参考:
https://stackoverflow.com/questions/4181861/src-refspec-master-does-not-match-any-when-pushing-commits-in-git

10-03 22:38