创建局域网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 "------------------------------------------------------------------------"
相关推荐
阿火~1 天前
Git 项目配置与推送完整指南
git
j7~1 天前
【Git】《Git 系列指南(二):Git基本操作与 reset 三种模式》
运维·git·git安装·git基本操作·git配置·创建git仓库·git reset三种模式
多加点辣也没关系1 天前
Git - 的安装与使用
大数据·git
帅次1 天前
Git 常用命令汇总
git·软件工程·开发工具·版本控制·git教程·代码管理·git命令
陈皮波比茶1 天前
git学习
git·学习
那年窗外下的雪.2 天前
AIDC 学习日志|第 14 天|MAC Flapping 与 EVPN 多归属分层排障
网络·git·学习·macos·github·spine
FlyWIHTSKY2 天前
本地文件夹转化为 Git 仓库,并推送到远程平台创建一个全新的仓库
git
必须会一定会2 天前
AI 编程隐私保护清单:API Key、代码上传、Agent 权限与 Git 历史排查
人工智能·git·ai编程
云计算磊哥@2 天前
运维开发宝典061-CICD_版本控制器git
运维·git·运维开发
晨枫阳2 天前
.gitignore 文件的真正含义
git