-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathgit-setup
executable file
·49 lines (45 loc) · 1.1 KB
/
git-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# Set up a git repository if one doesn't exist, add all files and make an initial commit.
#
# - Set up a git repository in the current working directory:
#
# `git-setup`
#
# - Set up a git repository in a custom directory:
#
# `git-setup {{path/to/repository}}`
#
# - Set up a git repository in the current working directory with a custom commit message:
#
# `git-setup -m {{commit_message}}`
#
# - Set up a git repository in the custom directory with a custom commit message:
#
# `git-setup -m {{commit_message}} {{path/to/repository}}`
#
# ---
# Based on https://github.com/tj/git-extras/blob/master/bin/git-setup
#
# Author: Nick Plekhanov, https://nikkhan.com/
# License: MIT
# https://github.com/nicksp/dotfiles
COMMIT_MESSAGE='Initial commit'
if [ "$1" == "-m" ]; then
COMMIT_MESSAGE=$2
shift
shift
fi
gitdirexists() {
if [ -d ".git" ]; then
echo ".git directory already exists, aborting"
exit 1
fi
}
dir=$(test -z "$*" && echo "." || echo "$*")
mkdir -p "$dir" \
&& cd "$dir" \
&& gitdirexists \
&& git init \
&& git add . \
&& git commit --allow-empty -m "$COMMIT_MESSAGE"