1. git push 免密码

使用https协议

1.使用文件创建用户名和密码
文件创建在用户主目录下:

vim ~/.git-credentials

https://USERNAME:[email protected]

2.添加git config内容

git config --global credential.helper store

执行此命令后,用户主目录下的.gitconfig文件会多了一项:

[credential]
helper = store

重新git push就不需要用户名密码了。

使用ssh协议

首先生成密钥对:

ssh-keygen -t rsa -C "youremail"

接下来按照提示操作,默认可以一路往下。

然后将生成的位于~/.ssh/id_rsa.pub的内容复制到你github setting里的ssh key中。

复制之后,如果你还没有克隆你的仓库,那你直接使用ssh协议用法:[email protected]:yourusername/yourrepositoryname克隆就行了。

如果已经使用https协议克隆了,那么按照如下方法更改协议:

git remote set-url origin
[email protected]:yourusername/yourrepositoryname.git

Done!


2. git add 使用tab键自动补全的中文文件名乱码

文件名乱码如下所示:

乱码
乱码

解决方法为:

git config --global core.quotepath false

效果如下:

效果
效果

可以看出中文已经正确显示了。


3. git 迁移仓库到另外一个仓库

# 仅保留历史提交信息
git clone --bare yourrepository

然后在你的其他服务,比如gogs新建一个仓库,然后进入你上步克隆出的仓库中,执行:

git push --mirror yourNewRepository

然后你就可以删除原来的仓库,然后git clone新仓库就行了。