创建局域网git裸仓库

创建局域网git裸仓库

不说废话,直接上脚本

bash 复制代码
#!/bin/bash

# 获取脚本所在的目录
script_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ $# -eq 0 ]; then
  echo "请提供仓库的名称作为参数。"
  exit 1
fi

repo_name=$1
repo_path="$script_path/$repo_name.git"
ip_address=$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | grep -v 'inet6' | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
url="ssh://root@$ip_address$script_path/$repo_name.git"


# 检查是否已经存在同名目录或文件
if [ -e $repo_path ]; then
  echo "目录或文件 '$repo_name' 已经存在。请使用其他名称。"
  exit 1
fi

# 切换到脚本所在目录
cd $script_path



# 创建裸仓库
git init --bare $repo_path


echo "------------------------------------------------------------------------"
echo ""
echo "裸仓库 '$url' 创建成功。"
echo ""
echo "------------------------------------------------------------------------"

cat << EOF

# 使用教程:

## Git 全局设置:

git config --global user.name "DerekLiu"
git config --global user.email "yjkhtddx@sina.com"

## 创建 git 仓库:

mkdir $repo_name
cd $repo_name
git init 
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin $url
git push -u origin "master"

## 已有仓库?

cd existing_git_repo
git remote add origin $url
git push -u origin "master"

EOF
echo "------------------------------------------------------------------------"
相关推荐
liuxin_072513 分钟前
phpstorm 操作git 分支合并到master
ide·git·phpstorm
cyforkk3 小时前
Git 进阶技巧:优雅合并初始提交与 Commit 规范详解
git
Elcker3 小时前
修改Git指定提交作者与时间
git
❀͜͡傀儡师3 小时前
Apifox投毒事件深度分析报告:供应链攻击窃取SSH密钥与Git凭据
git·ssh·apifox
云梦谭4 小时前
Git 环境定制常用命令
git
SuperEugene4 小时前
前端 Git 协作规范实战:commit message + 分支管理 + 合并流程,告别冲突与混乱|工程化与协作规范篇
前端·javascript·vue.js·git·前端框架
bu_shuo5 小时前
git中文显示不正确解决方法
git
Carsene6 小时前
艺术化你的 Git 提交:类型与图标(全网最全)的实践准则
git·github
身如柳絮随风扬6 小时前
Git 超详细学习笔记
笔记·git
原来是猿7 小时前
Git入门指南(一):从零开始,掌握Git基础操作
git