创建局域网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 "------------------------------------------------------------------------"
相关推荐
论迹7 分钟前
【Git】-- 多人协作
git·ubuntu
roamingcode1 小时前
从混沌到秩序:Git Diff 结构化报告的 Claude Code Skill 实践
人工智能·git·agent·skill·claude code·领域知识包·ai经验复用
ss2733 小时前
idea中git更新项目:将传入更改合并到当前分支,在传入更改上变基当前分支
java·git·intellij-idea
hopsky3 小时前
好用!Git 同时开发多个分支
git
secondyoung5 小时前
Git使用:rebase用法
c语言·经验分享·git·vscode
萧曵 丶6 小时前
CI/CD 流程
git·ci/cd
import_random6 小时前
[git版本控制]git push(详解)
git
bing_feilong8 小时前
gitee pull 总是需要用户名和密码,该如何设置?
git·gitee
毒鸡蛋8 小时前
GIT报错:Connection to git. closed by remote host.
git
ShallowLin8 小时前
Git简化分支管理(main+develop)
git