Shell 脚本小试牛刀(4) -- 创建 git 仓库
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Shell 脚本小试牛刀(4) -- 创建 git 仓库,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3057字,纯文字阅读大概需要5分钟。
内容图文
之前写过一个《 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 中已有简单描述。最简单的办法是你简单试一下吧。
对于客户端的 push ,在服务器段不会即时显示,如果你想要在服务器端git 仓库查看最新的仓库信息,请使用 “git reset --hard” 命令。
原文:http://blog.csdn.net/longerzone/article/details/35988567
内容总结
以上是互联网集市为您收集整理的Shell 脚本小试牛刀(4) -- 创建 git 仓库全部内容,希望文章能够帮你解决Shell 脚本小试牛刀(4) -- 创建 git 仓库所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。