git推送報錯: No path specified. See 'man git-pull' for valid url syntax或does not appear to be a git repo

  本地(windows)代碼想推送到linux本身搭建的git服務端,第一步是創建本地與服務端的關聯,第二步是本地推送到服務端。linux

  第一步須要看你的本地工程是否從git上clone來的,若是是clone來的那就不存在第一步了。若是是本地已經有了工程以後纔想同步到git上,那麼須要先到linux的git目錄下新增同名git倉庫並初始化。這裏以wlf-util工程爲例:git

cd git
mkdir wlf-util.git
cd wlf-util.git
git --bare init

  接着修改用戶屬主和用戶組屬主(這裏用戶和用戶組咱們都用git),並讓git倉庫有執行權限:windows

cd ..
chgrp git wlf-util.git -R
chown git wlf-util.git
chmod 775 wlf-util.git

  搞完上面這兩步後用ll命令看到的應該是這樣的:bash

drwxrwxr-x 7 git git 4096 Mar 17 21:54 wlf-util.git

  搞完服務端接着搞本地客戶端,打開本地windows下的git bash:app

cd workspace/wlf-util
git init
git remote add origin ssh://111.11.111.11/git/wlf-util.git

  這樣就創建了本地客戶端與遠程git服務端的鏈接了,本地的git倉庫wlf-uitl就能夠push給服務端的同名git倉庫了。但此時咱們本地配置的遠程url的路徑不對,因此會報以下錯誤:ssh

git push -u origin master
fatal: No path specified. See 'man git-pull' for valid url syntax

  告訴你沒有url連接,或者會說url不是一個倉庫:fetch

git push -u origin master
fatal: '/git/wlf-util.git' does not appear to be a git repository
fatal: Could not read from remote repository.

  那麼正確的git連接長啥樣呢?能夠先在本地客戶端執行以下命令來參考下ui

git remote -v
origin  ssh://111.11.111.11:wlf-util.git (fetch)
origin  ssh://111.11.111.11:wlf-util.git (push)

  從上面命令結果看,該遠程url沒有加入用戶,咱們本身加(還記得上面咱們設置的用戶git嗎?)。從新關聯服務端git以前,先把老的url刪掉url

git remote rm origin
git remote add origin git@111.11.111.11:wlf-util.git

  這樣第一步就結束了,第二步的問題也就來了:spa

$ git push -u origin master
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (10/10), 3.48 KiB | 891.00 KiB/s, done.
Total 10 (delta 0), reused 0 (delta 0)
remote: error: insufficient permission for adding an object to repository databa                                                                                                                se ./objects
remote: fatal: failed to write object
error: remote unpack failed: unpack-objects abnormal exit
To 111.11.111.11:wlf-util.git
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'git@111.11.111.11:wlf-util.git'

  其實第二步的問題在設置第一步時已經埋下了。還記得這兩條命令嗎:

chown git wlf-util.git
chmod 775 wlf-util.git

  它們少了一個參數-R,致使wlf-util.git裏的用戶和權限不對,天然沒法在客戶端push時寫入服務端了。解決辦法也很簡單:進入linux下git目錄

chown -R git wlf-util.git
chmod -R 775 wlf-util.git

  這時再回到windows下用git bash就能夠push了:

 git push -u origin master
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (10/10), 3.48 KiB | 891.00 KiB/s, done.
Total 10 (delta 0), reused 0 (delta 0)
To 111.11.111.11:wlf-util.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

  之後再push無需再加上-u從新配置了。

相關文章
相關標籤/搜索