git 使用和常見bug

初次在本地配置git時
安裝完成後,還需要最後一步設置,在命令行輸入:

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

因爲Git是分佈式版本控制系統,所以,每個機器都必須自報家門:你的名字和Email地址。你也許會擔心,如果有人故意冒充別人怎麼辦?這個不必擔心,首先我們相信大家都是善良無知的羣衆,其次,真的有冒充的也是有辦法可查的。

注意git config命令的–global參數,用了這個參數,表示你這臺機器上所有的Git倉庫都會使用這個配置,當然也可以對某個倉庫指定不同的用戶名和Email地址

git 添加多個remote origin

要關聯一個遠程庫,使用命令git remote add origin git@server-name:path/repo-name.git

關聯後,使用命令git push -u origin master第一次推送master分支的所有內容;

此後,每次本地提交後,只要有必要,就可以使用命令git push origin master推送最新修改;

添加另一個遠程庫,同樣的命令,不過名字不能是origin

查看remote

git remote -v

git 設置和取消代理

設置如下(可複製):

git config --global https.proxy http://127.0.0.1:1080

git config --global https.proxy https://127.0.0.1:1080


//only below two lines for ss
git config --global http.proxy 'socks5://127.0.0.1:1080' 
git config --global https.proxy 'socks5://127.0.0.1:1080'

取消

git config --global --unset http.proxy

git config --global --unset https.proxy

ssh創建rsa

ssh-keygen -t rsa -C "[email protected]"

git 【端口拒絕解決方案】ssh: connect to host github.com port 22: Connection refused

ssh 端口別拒絕後,切換成 https協議連接github

查看git設置

git config --global --list
會顯示賬號,郵箱,http端口代理等信息

config 配置指令

git config

config 配置有system級別 global(用戶級別) 和local(當前倉庫)三個 設置先從system-》global-》local  底層配置會覆蓋頂層配置 分別使用–system/global/local 可以定位到配置文件

  • 查看系統config

git config --system --list

  • 查看當前用戶(global)配置

git config --global  --list

  • 查看當前倉庫配置信息

git config --local  --list

git 更新

1、首先查看一下自己的版本是不是低於最新版:

git --version

2、若是,添加Git官方的軟件源:

sudo add-apt-repository ppa:git-core/ppa

3、接着更新一下軟件列表,就可以直接升級安裝了:

sudo apt update
sudo apt install -f
sudo apt upgrade

git bug

1

fatal: unable to access 'http://202.120.37.223:10080/SAIC_YSG/camera_calibration.git/': Failed to connect to 127.0.0.1 port 1080: Connection refused

端口代理取消

git config --global --unset http.proxy
git config --global --unset https.proxy

2

$ git push -u gitlab_fsTeam_origin  all     
error: src refspec all does not match any.
error: failed to push some refs to '[email protected]:ym825/fs_front_surroud.git'

主要的問題是你的linux系統並不信任你所要git的網站,所以通不過系統安全認證。解決方案有兩個:第一,告訴系統這個網站是可信任的;第二,關閉系統的安全認證,這個有些極端了。

1 告訴系統這個網站是可信任的

由於這個方法操作起來比較繁瑣,我並沒有採用這種方法,但是將這種方法的具體步驟提供給大家。

You need to check the web certificate used for your gitLab server, and add it to your </git_installation_folder>/bin/curl-ca-bundle.crt. 
To check if at least the clone works without checking said certificate, you can set: 
export GIT_SSL_NO_VERIFY=1 
or 
git config --global http.sslverify false

But that would be for testing only, as illustrated in “SSL works with browser, wget, and curl, but fails with git“, or in this blog post.

Check your GitLab settings, a in issue 4272.

To get that certificate (that you would need to add to your curl-ca-bundle.crt file), type a:

echo -n | openssl s_client -showcerts -connect yourserver.com:YourHttpGilabPort 2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'

(with yourserver.com being your GitLab server name)

To check the CA (Certificate Authority issuer), type a:

echo -n | openssl s_client -showcerts -connect yourserver.com:YourHttpGilabPort 2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'| openssl x509 -noout -text | grep "CA Issuers" | head -1

to identify the location of curl-ca-bundle.crt, you could use the command

curl-config --ca

2 關閉系統的安全認證
簡單粗暴的方式,關閉驗證。這種方式能在很短時間內收到效果,如果沒有耐心進行上面的設置的話,可以採用下面的命令。打開終端,在命令行中輸入如下命

export GIT_SSL_NO_VERIFY=1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章