为什么不能将我的 wordpress 目录推送到远程 github 存储库?

Why can't push my wordpress directory into remote github repository?

目标:将 /var/www/html/wp 推送到远程 git 集线器存储库中的 newstart。

ssh -T git@github.com
You've successfully authenticated, but GitHub does not provide shell access.

ssh 和 github 状态良好。

远程

1.To 在 git 中心网页中创建一个名为 newstart 的新项目。

本地

2.cd /var/wwww/html/wp
3.sudo git 初始化
4.git 添加 *
5.git 推送原点大师
错误:src refspec master 不匹配。
错误:无法将某些引用推送到 'origin'

感谢ffledgling,添加了两个命令。

git commit -m "First commit" 
git remote add origin git+ssh://git@github.com/someone/newstart.git 

git push origin master 
To git+ssh://git@github.com/someone/newstart.git 
 ! [rejected]        master -> master (fetch first) 
error: failed to push some refs to 'git+ssh://git@github.com/someone/newstart.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. 

现在如何将 /var/www/html/wp 推送到远程 github 存储库?

我认为您需要先在 github 创建存储库: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

  1. 你没有git提交。
  2. 你没有告诉 git origin 是什么意思。你必须:

    $ git remote add origin remote repository URL
    

查看说明here

1.git push -f origin master 解决问题:failed to push some refs to...在git push命令中加上-f参数。
2. 将 sudo git init 更改为 git init
为什么要把sudo git init改成git init?

如果.git是由sudo git init创建的,git push会有权限问题-f 原始主机.

ls -al .
total 204
drwxr-xr-x  6 www-data www-data  4096 Jan  1 19:42 .
drwxr-xr-x  5 root     root      4096 Dec 12 22:27 ..
drwxr-xr-x  8 root     root      4096 Jan  1 21:02 .git

如果 .git 是由 git init 创建的,不会git push -f origin master.

ls -al .
total 204
drwxr-xr-x  6 www-data www-data  4096 Jan  1 19:42 .
drwxr-xr-x  5 root     root      4096 Dec 12 22:27 ..
drwxr-xr-x  8 debian8  debian8   4096 Jan  1 21:02 .git

.git 目录的所有权将阻止执行 git push -f origin master

干得好。

error: failed to push some refs to 'git+ssh://git@github.com/someone/newstart.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

现在推送

git push origin <branch-name>

If the push still does not work saying that remote does not exists. Add it.

git remote add origin <path/to/your/remote/repo>