Shell 脚本小试牛刀(4) -- 创建 git 仓库
来源:互联网 发布:匡恩网络武汉 编辑:程序博客网 时间:2024/05/18 17:27
之前写过一个《Git 使用及进阶实战》,其中讲解了很多Git 的基本用法,包括创建仓库等使用以及一些错误排除,还是挺好的 GIT 普及博文。
我经常会在本地家用主机 /服务器上创建 git 仓库,可能一个语言的学习或者一个项目都需要一个git 仓库。不得不说创建仓库还是挺烦人的,有的时候会遗漏或者忘记命令,于是我写了一个简单的脚本来简化创建GIT 仓库的繁杂无趣的过程:
- #!/bin/bash
- # (C) 2014 Yunlong Zhou <reaper888@yeah.net>
- # Under licence GPL
- # File : mkgit.sh
- # Introduction:
- # This script is using for create a git repository
- # Useage :
- # Server Part :
- # $ ./mkgit.sh
- # Please input the git name you want to create: git-test <-- Input git repository name
- # Now create a dir named "git-test"
- # Please config user name: zyl <-- Input your name to recognise in git log
- # Got your user name : "zyl"
- # Please config user email address: reaper888@yeah.net <-- your email address
- # Got your user email address : "reaper888@yeah.net"
- # Initialized empty Git repository in /home/pi/repository/git-test/.git/
- # [master (root-commit) 4e52852] For initialize the git repository -- git-test
- # 1 file changed, 1 insertion(+)
- # create mode 100644 README
- # pi@192.168.2.226's password: <-- Need to input your IP address
- # Everything up-to-date <-- Done
- # $ cat git-test/.git/config
- # ...
- # url = pi@192.168.2.226:/home/pi/repository/git-test
- # \ /
- # ----> This part is important <----
- # Client Part:
- # $ git clone pi@192.168.2.226:/home/pi/repository/git-test
- # \--> git clone username@url-above, other username is ok(if authority is ok)
- # Cloning into 'git-test'...
- # pi@192.168.2.226's password: <-- input your password
- # remote: Counting objects: 3, done.
- # Receiving objects: 100% (3/3), 269 bytes, done.
- # remote: Total 3 (delta 0), reused 0 (delta 0)
- if read -t 15 -p "Please input the git name you want to create: "
- then
- git_name=$REPLY
- echo "Now create a dir named \"$git_name\""
- else
- echo -e "\nYou are too slow!"
- exit -1
- fi
- if read -p "Please config user name: "
- then
- user_name=$REPLY
- echo "Got your user name : \"$user_name\""
- fi
- if read -p "Please config user email address: "
- then
- user_email=$REPLY
- echo "Got your user email address : \"$user_email\""
- fi
- cur_user=`who | grep pts/0 | cut -d ' ' -f1`
- mkdir $git_name
- cd $git_name
- cur_address=`pwd`
- ip_addr=`sudo ifconfig | grep "inet addr" | cut -d":" -f2 | cut -d " " -f1 |sed "/127*/d"`
- if [ $? -ne 0 ]
- then
- if read -p "Sorry, get your IP address error, please input manually: "
- then
- ip_addr=$REPLY
- echo "Got your IP address : \"$ip_addr\""
- fi
- fi
- #git --bare init --shared
- git init
- echo "This is the first file of $git_name repository" > README
- git config --global user.name $user_name
- git config --global user.email $user_email
- git add README
- git commit -m "For initialize the git repository -- $git_name"
- git remote add origin $cur_user@$ip_addr:$cur_address
- git push origin master
- echo -e "[receive]\n\tdenyCurrentBranch = ignore" >> $cur_address/.git/config
此脚本是用来创建GIT 仓库的,创建好后客户端克隆使用即可,具体如何使用在脚本前部分的Usage 中已有简单描述。最简单的办法是你简单试一下吧。
0 0
- Shell 脚本小试牛刀(4) -- 创建 git 仓库
- Shell 脚本小试牛刀(4) -- 创建 git 仓库
- 【Git 教程(4)】 Git创建仓库
- Shell 脚本小试牛刀(2) -- git仓库的选取以及迁移
- Shell 脚本小试牛刀(2) -- git仓库的选取以及迁移
- 【Git】Git创建仓库
- git 创建服务端库Shell脚本
- 服务器端Git仓库的创建(Ubuntu)
- (转载)git 创建远程仓库详解
- git 简单创建仓库
- git 创建远程仓库
- git 创建远程仓库
- git创建远程仓库
- git:仓库创建
- git 创建远程仓库
- 创建git私有仓库
- git 创建远程仓库
- 创建git 仓库
- Struts2 OGNL
- java中四种操作(DOM、SAX、JDOM、DOM4J)xml方式详解与比较
- Linux之convert命令
- Duilib滑动条的使用
- 设计模式之简单工厂模式
- Shell 脚本小试牛刀(4) -- 创建 git 仓库
- ioctl 和unlock_ioctl函数讨论
- java的构造块静态块
- 几个经常用到的常规class
- duilib 捕捉Windos原生消息和自定义消息
- 为什么在App Store下载必须免费软件必须验证付款信息
- android 从服务器下载图片,并保存到本地
- Java中常用到的算法题
- JFinal 多数据源切换,实现数据迁移