git

git

安装

其实也不需要git bash啊,直接终端搞定一切

linux

使用

上传一个项目

  1. 进入文件夹folder_to_upload,git bash(命令行也行,能登陆到github账号就行)
  2. git init
  3. git add .
  4. git commit -m "随便写什么"
  5. github上新建一个仓库,不要勾选Initialize this repository with:Add a README file(创建之后能看到它的教程的)
  6. 将本地仓库与 GitHub 仓库关联git remote add origin https://github.com/用户名/仓库名.git
  7. git branch -M main
  8. git push -u origin main

bash流水线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

# 检查是否提供 commit 信息
if [ -z "$1" ]; then
# 如果没有提供 commit 信息,使用默认值
commit_message="Auto commit: $(date '+%Y-%m-%d %H:%M:%S')"
echo "No commit message provided. Using default: \"$commit_message\""
else
# 使用用户提供的 commit 信息
commit_message="$1"
fi

# 自动添加、提交并推送
git add .
git commit -m "$commit_message"
git push

# 提示完成
echo "Changes have been added, committed with message \"$commit_message\", and pushed successfully!"

报错

权限问题

  1. remote: Support for password authentication was removed on August 13, 2021.
    1. 根据官方教程
    2. Settings,最下面的Developer settings,展开Personal access tokens,选中classic那个,Generate new token
    3. token名字随便,过期、用途选repo
    4. 将令牌复制到剪贴板。关闭页面后不能再出现,除非重新生成!
    5. 设置token,使用,填密码的时候粘贴token
    6. 将分支克隆到本地的仓库(xxx.github.io)中的.git文件夹复制到博客文件夹中
    7. 在博客目录下执行命令同步到远程的hexo分支
      1
      2
      3
      git add -A
      git commit -m "备份Hexo(提交的描述)"
      git push origin hexo