標籤:erro comm 9.png objects touch tin 問題 工程 使用者名稱
之前部署的gitlab代碼託管平台,採用ssh方式串連gitlab,在客戶機上產生公開金鑰上傳到gitlab的SSH-Keys裡,則git clone下載和git push上傳都沒問題,這種方式很安全。
後來應開發同事要求採用http方式串連gitlab,那麼首先將project工程的“Visibility Level”改為“Public”公開模式,並且要保證gitlab的http連接埠像客戶機開放。
後面發現了一個問題:
http方式串連gitlab後,git clone下載沒有問題,但是git push上傳有報錯:
error: The requested URL returned error: 401 Unauthorized while accessing http://git.xqshijie.net:8081/weixin/weixin.git/info/refs
fatal: HTTP request failed
或者
The requested URL returned error: 403 Forbidden while accessing
執行個體如下:
假設git的url為http://git.wangshibo.net
[[email protected] ~]# mkdir /root/git
[[email protected] ~]# cd /root/git
[[email protected] git]# git init .
[[email protected] git]# git clone http://git.wangshibo.net:8081/weixin/weixin.git
Initialized empty Git repository in /root/git/weixin/.git/
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
上面可以看出,已經能成功git clone下代碼
[[email protected] git]# ll
total 4
drwxr-xr-x. 3 root root 4096 Nov 30 15:58 weixin
[[email protected] git]# cd weixin/
[[email protected] weixin]# ll
total 8
-rw-r--r--. 1 root root 15 Nov 30 15:58 heihei
-rw-r--r--. 1 root root 1 Nov 30 15:38 README.md
現在測試下git push
[[email protected] weixin]# git rm heihei
[[email protected]iu weixin]# touch test.file
[[email protected] weixin]# echo "123456" > test.file
[[email protected] weixin]# git add .
[[email protected] weixin]# git commit -m "this is a test"
[[email protected] weixin]# git push //或者git push -u origin master
error: The requested URL returned error: 401 Unauthorized while accessing http://git.wangshibo.net:8081/weixin/weixin.git/info/refs
fatal: HTTP request failed
解決辦法:
在代碼的.git/config檔案內[remote "origin"]的url的gitlab網域名稱前添加gitlab註冊時的“使用者名稱:密碼@”
如下,gitlab的使用者名稱是wangshibo,假設密碼是[email protected]!h8
查看gitlab介面裡的登陸使用者名稱:
然後修改代碼裡的.git/config檔案
[[email protected] weixin]# cd .git
[[email protected] .git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://git.wangshibo.net:8081/weixin/weixin.git
[branch "master"]
remote = origin
merge = refs/heads/master
修改如下:
[[email protected] .git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://wangshibo:[email protected][email protected]git.wangshibo.net:8081/weixin/weixin.git
[branch "master"]
remote = origin
merge = refs/heads/master
git push上傳代碼到gitlab上,報錯401或403