github 杂记

目录


常用加速与下载

加速下载 github 代码:

  1. 登录码云
  2. 新建仓库
  3. 导入已有仓库,粘贴 github 仓库地址
  4. 创建后即可直接下载

获取 github token


github token push

  • https://cxvh:${GITHUB_TOKEN}@github.com/cxvh/blogs.git
  • git config --global user.name "cxvh"
  • git config --global user.email "***@qq.com"

发布 github packages

  1. 初始化 package.json
    npm init --scope=cxvh
    其中cxvh必须是你的github用户名,其他随意填写。
  2. 添加 publishConfigpackage.json
    "publishConfig": { "registry": "https://npm.pkg.github.com/" }
  3. 登录
    npm login --registry=https://npm.pkg.github.com/
    用户名为github账号,密码用github token,邮箱用github邮箱
  4. package.jsonname 格式为 @登录名/包名,如:@cxvh/hello-world-npm
  5. 发布
    npm publish

github action 配置

根据时间自动构建,官方文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
on:
schedule:
- cron: '0 * * * *' # 每小时运行一次
# - cron: '0 6 * * *' # 每天6点
# - cron: '0 6 1 * *' # 每月1号6点
# - cron: '*/30 * * * *' # 每30分钟
# - cron: '0 19 */7 * *' # 每7天的19点
workflow_dispatch: # 手动触发

pushpull_request 触发构建:

1
2
3
4
5
6
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

action 克隆到当前仓库示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
name: 每天自动同步仓库
on:
schedule:
- cron: '0 19 * * *'
workflow_dispatch:
jobs:
copy:
runs-on: ubuntu-latest
steps:
- name: 同步到当前仓库
uses: andstor/copycat-action@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
src_path: /.
dst_path: /
dst_owner: code-ba
dst_repo_name: rss-reader
dst_branch: main
src_branch: main
clean: true
username: cxvh
email: ${{ secrets.PERSONAL_EMAIL }}

报错解决记录

1. 密钥生成失败

  • Windows 下执行 ssh-keygen 写入权限不够报错:
    1
    Saving key ".../id_rsa" failed: No such file or directory
  • 解决:进入文件夹 C:\Users\用户\.ssh\gitlab 再执行 ssh-keygen

2. git rebase 报错

  • 历史中不连续的 commit 合并 git rebase -i head~3,报错如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    interactive rebase in progress; onto bbef1ea
    No commands done.
    Next commands to do (3 remaining commands):
    s ae093ef 更新 circleci 配置文件
    s 1ab23ac 更新 circleci 配置文件2
    (use "git rebase --edit-todo" to view and edit)
    You are currently editing a commit while rebasing branch 'main' on 'bbef1ea'.
    (use "git commit --amend" to amend the current commit)
    (use "git rebase --continue" once you are satisfied with your changes)

    nothing to commit, working tree clean
  • 解决:回到 rebase 执行前状态
    git rebase --abort

3. git push 拼写错误

  • 错误命令:git push orgin main
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    fatal: 'orgin' does not appear to be a git repository
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
    #
    $ git push orgin主要
    致命的:“orgin”似乎不是git存储库
    致命:无法从远程存储库读取。

    请确保您具有正确的访问权限
    并且存储库存在。
  • 解决:删除 .git 目录,重新 git init 并配置远程仓库。

4. git push SSL 报错

1
fatal: unable to access 'https://github.com/cxvh/cxvh-cli-test.git/': OpenSSL SSL_connect: Connection was reset in connection to github.com:443
  • 解决:将 https 链接改为 ssh 链接
    git remote set-url origin git@github.com:cxvh/cxvh-cli-test.git