之前部署的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
[root@test-huanqiu ~]# mkdir /root/git
[root@test-huanqiu ~]# cd /root/git
[root@test-huanqiu git]# git init .
[root@test-huanqiu 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下代码
[root@test-huanqiu git]# ll
total 4
drwxr-xr-x. 3 root root 4096 Nov 30 15:58 weixin
[root@test-huanqiu git]# cd weixin/
[root@test-huanqiu 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
[root@test-huanqiu weixin]# git rm heihei
[root@test-huanqiu weixin]# touch test.file
[root@test-huanqiu weixin]# echo "123456" > test.file
[root@test-huanqiu weixin]# git add .
[root@test-huanqiu weixin]# git commit -m "this is a test"
[root@test-huanqiu 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注册时的“用户名:密码@”
另外发现这个用户要在对应项目下的角色是Owner或Master才行,如果是Guest、Reporter、Developer,则如下操作后也是不行。
如下,gitlab的用户名是wangshibo,假设密码是HU@wew12378!h8

查看gitlab界面里的登陆用户名:

然后修改代码里的.git/config文件
[root@test-huanqiu weixin]# cd .git
[root@test-huanqiu .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

修改如下:
[root@test-huanqiu .git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://wangshibo:HU@wew12378!h8@git.wangshibo.net:8081/weixin/weixin.git
[branch "master"]
remote = origin
merge = refs/heads/master

然后再次git push,发现可以正常提交了!
[root@test-huanqiu weixin]# git push
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 297 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://wangshibo:HUIhui1987521@git.xqshijie.net:8081/weixin/weixin.git
8fcb559..6c97b56 master -> master

------------------------------------------------------------------------------------------------------------------------------------
可以创建一个用户名作为admin管理员,然后将这个用户名和密码添加到项目代码的.git/config里面,如上操作!
如果不是管理员,则至少对当前代码具有owner或master权限。

这样,在.git/config文件里添加这个用户名和密码权限,然后其他人在git push的时时候都使用这个文件进行覆盖。

其他人在首次git clone下载代码的时候,需要进行--global全局配置,然后就可以在gitweb控制台里追踪到每个操作者的提交记录了!

git push上传代码到gitlab上,报错401/403(或需要输入用户名和密码)的更多相关文章

  1. git push上传代码到gitlab上,报错401或403

    之前部署的gitlab代码托管平台,采用ssh方式连接gitlab,在客户机上产生公钥上传到gitlab的SSH-Keys里,则git clone下载和git push上传都没问题,这种方式很安全. ...

  2. [Jenkins Git] 在Jenkins上拉代码总是失败,跑去本地看,提示输入用户名和密码,但是Jenkins上已经配置了正确的用户名和密码

    git config --global credential.helper manager

  3. MAC使用pycharm上传代码到Github上

    本人的电脑已经在GitHub中添加成功了SSH keys! 以下为在pycharm中上传代码到Github的步骤. Step1:打开pycharm,preferences---plugins(插件)选 ...

  4. react-native 在Xcode上传到iTunes Connect里报错

    在xcode里面点击“upload to app store”的时候,提示“the session's status is FAILED and the error description is 'C ...

  5. webstorm 上传代码到gitlab

    1. 2. 3.push 4.填写上传url

  6. 上传代码到github上

    初始化 git init 添加远程仓库 git remote add origin[仓库名] 仓库地址 添加文件 git add . 本地提交 git commit -m 'message' 拉去远程 ...

  7. maven tomcat插件上传项目到tomcat服务器报错SEVERE: One or more listeners failed to start.

    以前觉了maven依赖设置很简单,就是将手动导入jar包转化为自动下载导入 但发现的一个问题, 在使用maven插件tomcat打包上传工具时 tomcat-maven-plugin <buil ...

  8. 批量上传文件或者上传大文件时 gateWay报错DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144

    一.描述 最近在批量上传文件时网关出现了异常,后面发现上传大文件也会出现文件超过256发生异常,异常信息如下: org.springframework.core.io.buffer.DataBuffe ...

  9. springMVC:为MultipartFilte配置了上传文件解析器,报错或不能使用

    一.问题描述为支持restful风格请求,并且应对可能上传文件的情况,需要在配置hiddenHttpMethodFilter过滤器之前配置MultipartFilter.目的是让MultipartFi ...

随机推荐

  1. python第八天)——购物车作业优化完成

    发现之前的三级菜单代码有BUG现已经修改过来了 购物车程序:启动程序后,输入用户名密码后,如果是第一次登录,让用户输入工资,然后打印商品列表允许用户根据商品编号购买商品用户选择商品后,检测余额是否够, ...

  2. sql server 如何查询出数据库作业所有者的信息并完成批量替换

    今天数据库对入职一年的我建立了独立的数据库账号,之前我是和其他同事共享的,之前的所有者账号被废弃了,这时导致很多数据库作业执行失败. 下面是说明如何把之前所有的作业的所有者替换成正在使用的账号: 下面 ...

  3. 离群点检测与序列数据异常检测以及异常检测大杀器-iForest

    1. 异常检测简介 异常检测,它的任务是发现与大部分其他对象不同的对象,我们称为异常对象.异常检测算法已经广泛应用于电信.互联网和信用卡的诈骗检测.贷款审批.电子商务.网络入侵和天气预报等领域.这些异 ...

  4. Nginx实现页面缓存

    页面缓存 1.缓存指令 Nginx的缓存配置比较直观简单,具体有下面几个指令需要知道: A.proxy_cache_path 格式:proxy_cache_path path [levels=numb ...

  5. .net core 入坑经验 - 3、MVC Core之jQuery不能使用了?

    在View中添加了一段jQuery代码用来控制一个按钮的点击事件.发现运行时提示$对象没有定义,经过在浏览器右键查看源文件发现,script代码在引用jquery代码的上方,执行时jquery还未引入 ...

  6. January 23rd, 2018 Week 04th Tuesday

    Remembrance is a form of meeting, forgetfulness is a form of freedom. 记忆是一种相遇,遗忘是一种自由. Cherish those ...

  7. VMware NAT 设置原理

    1.网络地址转换(NAT):默认使用VMnet8 (强烈推荐) 这种访问模式指的是虚拟机不占用主机所在局域网的ip,通过使用主机的NAT功能访问局域网和互联网,意味着虚拟机可以访问局域网中的其他电脑, ...

  8. MetaMask/sw-controller

    https://github.com/MetaMask/sw-controller Service Worker Controller Used to register a service worke ...

  9. Linux系统学习之软件安装

    一.源码包编译安装 由于计算机无法直接执行用高级语言编写的源程序,因此想要运行程序,就需要一种机制来让计算机识别,这样程序才可能运行起来.一般来说,计算机中存在解释型和编译型两种语言. 所谓解释型语言 ...

  10. Java/JSP程序连接不上Mysql驱动问题解决方法

    错误提示: java.lang.ClassNotFoundException: com.mysql.jdbc.Driverat java.net.URLClassLoader$1.run(URLCla ...