Awesome Git

Install

MacOS

Proxy

Just set following cmdline:

git config --global http.proxy http://xxx
git config --global https.proxy http://xxx

Common git skill

关于git学习的资料,可以查看 git教程

Set git proxy

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

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.

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

Github Action

首先,github action 已经成为了软件开发领域不可获取的部分。

关于 Github Action 文档学习,

首先,需要创建 .github/workflow/xxx.yml目录文件。

下面是我在用的一些 Github Action

My config

Github Link

mkdocs.yml
name: GitHub Pages

on:
  push:
    branches:
      - main  # Set a branch name to trigger deployment
jobs:
  publish:
    name: Deploy Site
    runs-on: ubuntu-22.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

My Github Issues

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

https://www.raulmelo.me/_vercel/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgc3hakk3%2Fproduction%2F8b5476684f1dfe262c1d8c0abe8b9fca7124311a-1220x1381.png%3Fw%3D1220%26h%3D1381%26auto%3Dformat&w=1280&q=100

Github Save username and password

由于经常有开项目的习惯,存在多个账号,所以建议先设置local的 user.nameuser.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

Github CheatSheet

Title

Command

Meaning

Note

git config --global core.editor "vim"

修改编辑器

Row 2, column 1

Row 2, column 2

Row 2, column 3

MacOS