git推送報錯: No path specified. See 'man git-pull' for valid url syntax或does not appear to be a git repository以及remote: error: insufficient permission for adding an object to repository databa


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

  第一步需要看你的本地工程是否從git上clone來的,如果是clone來的那就不存在第一步了。如果是本地已經有了工程之后才想同步到git上,那么需要先到linux的git目錄下新增同名git倉庫並初始化。這里以ms-util工程為例:

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

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

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

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

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

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

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

  這樣就建立了本地客戶端與遠程git服務端的連接了,本地的git倉庫ms-uitl就可以push給服務端的同名git倉庫了。但此時我們本地配置的遠程url的路徑不對,所以會報如下錯誤:

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

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

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

  那么正確的git鏈接長啥樣呢?可以先在本地客戶端執行如下命令來參考下

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

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

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

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

$ 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:ms-util.git
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'git@111.11.111.11:ms-util.git'

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

chown git ms-util.git
chmod 775 ms-util.git

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

chown -R git ms-util.git
chmod -R 775 ms-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 116.62.136.56:ms-util.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

  以后再push無需再加上-u重新配置了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM