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

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