-
Notifications
You must be signed in to change notification settings - Fork 3
/
git.sh
executable file
·55 lines (55 loc) · 1.47 KB
/
git.sh
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
50
51
52
53
54
55
#!/usr/bin/env bash
script_name=$(basename "$0")
remote_branch=master
git_init() {
remote_url=$(git config --local --get remote.origin.url)
set -vuex
rm -rf ./.git && git init
git checkout --orphan latest_branch
git add -A .
git config user.name "limuGG" && git config user.email "-"
git commit -am "Initial commit"
test -n "$remote_url" && git remote add origin "$remote_url"
if test $# -eq 0 || test -z "$1" || test -z "$remote_url"; then
git checkout -b $remote_branch
git branch -D latest_branch
set +vuex
fi
if test "$1" = 'reset'; then
echo "git reset"
git checkout -b $remote_branch
git branch -D latest_branch
git fetch
git branch --set-upstream-to=origin/$remote_branch $remote_branch
set +vuex
fi
if test "$1" = 'pull'; then
echo "git pull"
git fetch
git checkout -b $remote_branch origin/$remote_branch
git branch -D latest_branch
git pull
set +vuex
fi
}
git_push() {
git_init "reset"
git push -f origin $remote_branch
git pull
}
git_add() {
git add -A .
git commit -am "update"
}
run() {
echo "$script_name"
case $1 in
git-init) shift 1 && git_init "$@" ;;
git-reset) shift 1 && git_init "reset" ;;
git-pull) shift 1 && git_init 'pull' ;;
git-push) shift 1 && git_push "$@" ;;
git-add) shift 1 && git_add "$@" ;;
*) echo "unknown command: $1" ;;
esac
}
run "$@"