1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GIthubにカレントディレクトリをプライベートでワンコマンドでぶん投げるシェルスクリプト

1
Last updated at Posted at 2019-12-20

いままで一旦Webブラウザでリポジトリつくってーとかやっていたけれどもコマンド一発でGitHubまでアップできるスクリプトを組みました。
仕事ではこんな雑なgit作業はできないけれど、個人使いならありとおもいます。すくなくとも私の幸福度はあがりました。
hubコマンドについてはググってください。
oauth_tokenとか設定が必要です。(401喰らいます)

  • (初回は)GitHubにリポジトリつくって
  • コミットしてpushする

-pでプライベートリポジトリ作成なのでパブリックで作りたいときはコマンドの-p消してください。
git-one-pushとかいうファイルにして実行権限与えて使います。
使い方としては作業が終わったら初回は./git-one-push "<RepositoryName>" "<Commitコメント>"、次回以降は./git-one-push "<Commitコメント>"でGitHubにプッシュまでしてくれ、そこそこ使えます。

USERNAME変数を適宜自分のものに変えてください

# ! /bin/bash
############
# setting
############
USERNAME=yourname

############
# functions
############
function git_init() {
  git init
  REPONAME=$1
  if [ -z "$REPONAME" ]; then
    REPONAME=`date +"%Y%m%d%H%M%S"`
  fi
  hub create -p ${REPONAME} # publicにしたいなら-p消す
}
function git_commit_push() {
  MESSAGE=$1
  if [ -z "$MESSAGE" ]; then
    MESSAGE=`date +"%Y-%m-%d %H:%M:%S"`
  fi
  git add .
  git commit -m "$MESSAGE"
  git push --all
}

############
# main
############
cd `dirname $0`
if git rev-parse --git-dir > /dev/null 2>&1; then
  # git 管理中
  git_commit_push $1;
else
  # git 管理中ではない
  git_init $1;
  git_commit_push $2;
fi
hub browse

以上です。よろしくおねがいします。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?