避免 Merge 提交
在使用 Git 提交代码时,我们会执行 git pull 命令。默认情况下,git pull 会执行 git fetch + git merge。当本地有提交且远程有更新时,Git 会创建一个合并提交,这会导致 Git 历史记录中出现大量 Merge 记录。
因此,更好的做法是使用 git pull --rebase。这种方式下,Git 会先暂存本地提交,拉取远程更新后,再将本地提交依次应用到最新的远程提交之上,从而保持提交历史的线性性,避免产生合并提交。
要启用 git pull --rebase,只需设置一次全局配置:
git config --global pull.rebase true
设置后,每次执行 git pull 时都会自动应用 --rebase 参数,避免产生不必要的合并提交。
Git 代理设置
使用 Github 时经常会遇到网络连接问题。即使你已经设置了浏览器代理,能够流畅访问 Github 网站,Git 命令行依然需要单独配置代理才能正常使用。
Git 配置代理方式如下:
git config --global http.proxy http://127.0.0.1:1080/
git config --global https.proxy http://127.0.0.1:1080/
配置完成后,你就可以流畅地使用 Git 命令操作 Github 了。