問題:gitlab開啟了雙因素認證
如進行了 OAuth configuration
在進行git操作時如下提示
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password.
解決辦法
1、生成 Personal access tokens
Scopes部分選擇write_repository即可,或者Scopes都選上,其他按需配置,復制Token,這個只顯示一次
2、使用 Personal access tokens
命令行進行git
操作,如
直接使用access token
拉取代碼:
git clone https://oauth2:生成的Access-TOKEN@gitlab.z_johnny.com/test/xxx.git
每次拉取代碼都需要加上access token
稍微有點麻煩,可以配置一下:
git config --global url."https://oauth2:生成的Access-TOKEN@gitlab.z_johnny.com".insteadof "https://gitlab.z_johnny.com"
配置好后,每次按正常的拉取方式拉取代碼就好了:
git clone https://gitlab.z_johnny.com/test/xxx.git
常見問題
Windows配置了token拉取失敗
Windows在c盤下的用戶目錄下的windows賬戶下,有一個gitconfig的隱藏文件,添加如下圖片中的兩行命令,里面的oauth2:后面就是token,替換為自己的token即可。比如"C:\Users\johnny\.gitconfig"
MacOS & Linux 配置了token拉取失敗
MacOS找到用戶目錄下的“.gitconfig”隱藏文件 添加如下兩行代碼,里面的token換成個人自己的token即可。
[url "https://oauth2:生成的Access-TOKEN@gitlab.z_johnny.com"]insteadof = gitlab.z_johnny.com