github/github/init.sh
2025-04-14 13:53:16 +08:00

29 lines
564 B
Bash
Executable File

#!/bin/bash
# 检查是否提供了目录和远程仓库地址参数
if [ -z "$1" ] || [ -z "$2" ]; then
echo "请提供要操作的目录和远程仓库地址."
exit 1
fi
# 进入指定目录
cd "$1" || { echo "无法进入目录 $1"; exit 1; }
# 添加安全目录
git config --global --add safe.directory "$1"
# 初始化 Git 仓库
git init
# 提交第一次更改
git commit -m "first commit"
# 创建并切换到 main 分支
git branch -M main
# 添加远程仓库
git remote add origin "$2"
# 推送到远程仓库
# git push -u origin main