ghqを使っているとリモートリポジトリもコンソールから簡単に作りたくなった(bitBucketとgithub用)
はじめに
ghqでローカルリポジトリを管理していまして、
結構快適なんですが、新規プロジェクトを作る際に、
リモートリポジトリの作成をWEB側でいちいち作るのが面倒くさくなってきました。
ということでコマンド一発でリモートリポジトリの新規作成とremote add、pushまでを行います。
尚、githubではオープンリポジトリ、bitbucketではプライベートリポジトリとして登録を行います、
インストールとか
bitbucketとgithubのcliツール&必要コマンドを導入します。
bb
$ pip install bitbucket-cli
$ touch ~/.bitbucket
$ chmod 600 ~/.bitbucket
$ vim ~/.bitbucket
~/.bitbucket
[auth]
username = <username>
password = <password>
[options]
scm = git
protocol = ssh
hub
$ brew install hub
wget
$ brew install wget
以下を~/.zshrc
に追記
~/.zshrc
function crrr() {
if [ ! -e .git ]; then
echo "please git init."
return
fi
local arr
arr=( `pwd | tr -s '/' ' '`)
local REPO=$arr[-1]
local OWNER=$arr[-2]
local SERVICE=$arr[-3]
case $SERVICE in
"bitbucket.org")
bb list | grep $OWNER/$REPO
if [[ $? == 0 ]]; then
echo "this repo is exist."
return
fi
echo "create repo in $SERVICE"
#crete_from_local代替
bb create -w $OWNER -c $REPO
git remote add origin [email protected]:${OWNER:l}/${REPO:l}.git
git push -u origin master
;;
"github.com")
wget -q --spider "https://github.com/$OWNER/$REPO"
if [[ $? == 0 ]]; then
echo "this repo is exist."
return
fi
echo "create repo in $SERVICE"
gh create $OWNER/$REPO
git push -u origin master
;;
*)
echo "no hit.";;
esac
}
source ~/.zshrc
で再設定しておきます。
実際の手順
手順
$ cd ~/repo/github.com/m0a
$ #新規プロジェクトを作成します
$ mkdir sample00
$ cd sample00
$ git init
$ echo "test create" > README.md
$ git add -A
$ git commit -m "init."
$ crrr
という感じで使います。
Author And Source
この問題について(ghqを使っているとリモートリポジトリもコンソールから簡単に作りたくなった(bitBucketとgithub用)), 我々は、より多くの情報をここで見つけました https://qiita.com/m0a/items/b49efde9ca74bdfad1ef著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .