Shell 指令碼小試牛刀(4) -- 建立 git 倉庫

來源:互聯網
上載者:User

標籤:git   指令碼   建立倉庫   

之前寫過一個《Git 使用及進階實戰》,其中講解了很多Git 的基本用法,包括建立倉庫等使用以及一些錯誤排除,還是挺好的 GIT 普及博文。

我經常會在本地家用主機 /伺服器上建立 git 倉庫,可能一個語言的學習或者一個項目都需要一個git 倉庫。不得不說建立倉庫還是挺煩人的,有的時候會遺漏或者忘記命令,於是我寫了一個簡單的指令碼來簡化建立GIT 倉庫的繁雜無趣的過程:

#!/bin/bash# (C) 2014 Yunlong Zhou <[email protected]>    # 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: [email protected]<-- your email address#       Got your user email address : "[email protected]"#       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#       [email protected]'s password: <-- Need to input your IP address#       Everything up-to-date<-- Done#       $ cat git-test/.git/config #       ...#       url = [email protected]:/home/pi/repository/git-test  #                \                                        /#                 ----> This part is important       <----#    Client Part:#       $ git clone [email protected]:/home/pi/repository/git-test#                      \--> git clone [email protected], other username is ok(if authority is ok)#       Cloning into 'git-test'...#       [email protected]'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: "thengit_name=$REPLY    echo "Now create a dir named \"$git_name\""else    echo -e "\nYou are too slow!"exit -1fi if read -p "Please config user name: "thenuser_name=$REPLY    echo "Got your user name : \"$user_name\""fiif read -p "Please config user email address: "thenuser_email=$REPLY    echo "Got your user email address : \"$user_email\""fi cur_user=`who | grep pts/0 | cut -d ' '  -f1`mkdir $git_namecd $git_namecur_address=`pwd`ip_addr=`sudo ifconfig | grep "inet addr" | cut -d":" -f2 | cut -d " " -f1 |sed  "/127*/d"`if [ $? -ne 0 ]thenif read -p  "Sorry, get your IP address error, please input manually: "then ip_addr=$REPLYecho "Got your IP address : \"$ip_addr\""fifi#git --bare init --sharedgit initecho "This is the first file of $git_name repository" > READMEgit config --global user.name $user_name git config --global user.email $user_email git add READMEgit commit -m "For initialize the git repository -- $git_name"git remote add origin [email protected]$ip_addr:$cur_addressgit push origin masterecho -e "[receive]\n\tdenyCurrentBranch = ignore" >> $cur_address/.git/config

此指令碼是用來建立GIT 倉庫的,建立好後用戶端複製使用即可,具體如何使用在指令碼前部分的Usage 中已有簡單描述。最簡單的辦法是你簡單試一下吧。


對於用戶端的 push ,在伺服器段不會即時顯示,如果你想要在伺服器端git 倉庫查看最新的倉庫資訊,請使用 “git reset --hard” 命令。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.