Shell script (4)-create a git Repository

Source: Internet
Author: User

I have written a git usage and advanced practice article, which explains many basic git usage, including creating a repository and troubleshooting some errors.

I often create a git repository on a local home host/Server. A git repository is required for learning a language or a project. I have to say that creating a repository is quite annoying. Sometimes I may miss or forget the command. So I wrote a simple script to simplify the complicated and boring process of creating a git Repository:

#!/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

This script is used to create a git repository. After the repository is created, the client can be cloned and used. A brief description of how to use this script is provided in the usage section before the script. The simplest way is to give it a try.


Client push is not immediately displayed in the server segment. If you want to view the latest Repository Information in the GIT repository on the server side, use the "Git reset -- hard" command.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.