简体   繁体   中英

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

Target :to push /var/www/html/wp in to newstart in remote github repository.

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

The ssh and github were in good status.

In remote

1.To create a new project named newstart in github web page.

In local

2.cd /var/wwww/html/wp
3.sudo git init
4.git add *
5.git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin'

Thank to ffledgling,two commands added.

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. 

How to push /var/www/html/wp into remote github repository now?

  1. You didn't git commit.
  2. You didn't tell git what origin means. You'll have to :

     $ git remote add origin remote repository URL 

See instructions here

1.git push -f origin master To solve the problem: failed to push some refs to... with -f parameter in git push command.
2. to change sudo git init into git init
Why change sudo git init into git init ?

If .git was created by sudo git init ,there will be permission problem for 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 root     root      4096 Jan  1 21:02 .git

If .git was created by git init ,there will not be permission problem for 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

The ownership of .git directory will prevent executing git push -f origin master .

Well done now.

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. 

The above error says that you currently are not in sync with the remote repository.

Sync

git pull --rebase

Now Push

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM