Awesome Git¶
Best Pratice for Git¶
git config --global core.editor vim
git config --global user.name "hotchilipowder"
git config --global user.email "h12345jack@gmail.com"
账户设置¶
之前在Mac用多个账户,经常出现要么不能git clone私有项目(因为是另外一个账户),要么错误的用了账户到别的repo中,并且一直管理上比较麻烦。
有如下的方案:
方案1: 不配置global
方案2: 配置global, 默认使用hotchilipowder的账号。
方案1的版本中,需要按照如下的方式清除默认的 credential.helper 。 对于
My Github Issues¶
MacOS osxkeychain¶
Mac 上清除 git osxkeychain 保存的登录名密码
git config --local --unset credential.helper
git config --global --unset credential.helper
git config --system --unset credential.helper
但是还有进一步删除这个文件下的配置, more detail see this link
git config --show-origin --get credential.helper
How to change default editor into vim¶
不太习惯使用 nano, 默认的nano比较难搞,改成 vim
git config --global core.editor vim
Permission to x denied to github-actions[bot]¶
遇到“Permission to "x" denied to github-actions[bot].”问题,按照下面的方法进行处理, see this link

Github Save username and password¶
由于经常有开项目的习惯,存在多个账号,所以建议先设置local的 user.name
和 user.email
,并且进一步设置, 当前的项目的存储方式,这样可以少输入密码
git config --local user.name "hotchilipowder"
git config --local user.email "h12345jack@gmail.com"
git config --local credential.helper cache
具体这些字段将会被写入到 project_xxx/.git/config
中,
例如:
[user]
name = hotchilipowder
email = h12345jack@gmail.com
[credential]
helper = cache
Config¶
Command |
Meaning |
Note |
---|---|---|
|
修改编辑器为Vim |
|
|
修改cache过期事件为1周=60 * 60 * 24 * 7 = 604800 |
|
|
设置默认的本地的crediential的username,避免每次都要重复输入。 |
No Password¶
Install¶
apt install git-all
see this link for recent release.
apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
cd tmp
curl -OL https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.38.5.tar.gz
tar -xvf git-2.38.5.tar.gz
./configure --prefix=$HOME/.local
make && make install
brew install git
Proxy¶
Just set following cmdline:
git config --global http.proxy http://xxx
git config --global https.proxy http://xxx
Common git skill¶
关于git学习的资料,可以查看 git教程
Change history user.name and user.email¶
这个需求我主要是多设备没设置user.name 或者 user.email导致有一些奇怪的用户出现在git history里面了。
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="you@example.com"
CORRECT_NAME="hotchilipowder"
CORRECT_EMAIL="h12345jack@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
当然,为了避免这些,最好还是设置一下 user.name和user.email.
git config --local user.name "hotchilipowder"
git config --local user.email "h12345jack@gmail.com"
Delete all history¶
这个需求比较常见,因为有些commit history确实不想让人看到,很愚蠢
git checkout --orphan latest_branch
git add .
git commit -m "Update"
git branch -D main
git branch -m main
Lazygit¶
Lazygit is a simple terminal UI for git commands.
Github Action¶
首先,github action 已经成为了软件开发领域不可获取的部分。
关于 Github Action 文档学习,
首先,需要创建 .github/workflow/xxx.yml
目录文件。
下面是我在用的一些 Github Action
My config¶
mkdocs.yml
name: GitHub Pages
on:
push:
branches:
- main
jobs:
publish:
name: Deploy Site
runs-on: ubuntu-24.04
environment: github-pages
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Install
shell: bash
run: |
pip install -r requirements.txt
sphinx-build -b html docs build
- name: Make snippets to rst
shell: bash
working-directory: snippets
run: |
python3 snippets.py
- name: Deploy Website
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
本项目使用的github,其主要包括以下功能:
安装依赖+构建文档
Make snippsts to rst
push html to github page
Self-hosted Action¶
最近,得知了Github Action可以Self-hosted了。基于这个特性,将会非常好的使用Github Action去替换Jenkin。
具体的步骤主要是按照要求进行安装即可。