UNPKG

1.66 kBapplication/x-shView Raw
1#!/bin/sh
2# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3#
4# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
5
6git_user_id=$1
7git_repo_id=$2
8release_note=$3
9
10if [ "$git_user_id" = "" ]; then
11 git_user_id="GIT_USER_ID"
12 echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
13fi
14
15if [ "$git_repo_id" = "" ]; then
16 git_repo_id="GIT_REPO_ID"
17 echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
18fi
19
20if [ "$release_note" = "" ]; then
21 release_note="Minor update"
22 echo "[INFO] No command line input provided. Set \$release_note to $release_note"
23fi
24
25# Initialize the local directory as a Git repository
26git init
27
28# Adds the files in the local repository and stages them for commit.
29git add .
30
31# Commits the tracked changes and prepares them to be pushed to a remote repository.
32git commit -m "$release_note"
33
34# Sets the new remote
35git_remote=`git remote`
36if [ "$git_remote" = "" ]; then # git remote not defined
37
38 if [ "$GIT_TOKEN" = "" ]; then
39 echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
40 git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
41 else
42 git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
43 fi
44
45fi
46
47git pull origin master
48
49# Pushes (Forces) the changes in the local repository up to the remote repository
50echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
51git push origin master 2>&1 | grep -v 'To https'
52