やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

Hubコマンドを使ってみた

Hubコマンドというものを見つけたので試してみた。

開発環境

hub

ダウンロード

hubをダウンロードする。

hub 2.2.8 for Windows 32-bitを選択した。

インストール

install.bat

解凍するとinstall.batファイルがあった。

怖いので、とりあえず中身を見てみたら、環境変数のPathをいじっているっぽい。

%RUNPS% "[Environment]::SetEnvironmentVariable('PATH', '%NEWPATH%', 'User')"

set HUB_BIN_PATH="%LOCALAPPDATA%\GitHubCLI\bin"
IF EXIST %HUB_BIN_PATH% GOTO DIRECTORY_EXISTS
mkdir %HUB_BIN_PATH%
set "path=%PATH%;%HUB_BIN_PATH:"=%"
call :appendToUserPath "%HUB_BIN_PATH:"=%"

どうやらPowerShellを使って環境変数を書き換えているっぽい。 そんなことができるのか知らないのだが。

ユーザ環境変数に以下のように追記するっぽい。

変数名
Path %LOCALAPPDATA%\GitHubCLI\bin

エラーになった

install.batを実行してみた。

コンソールが立ち上がったが、いつまでたっても何も表示されない。

しびれをきらしてEnterキーを押下したら、以下のように表示された。

install.bat

結局、インストールされなかった。ディレクトリも作成されず、環境変数も追記されていなかった。

自前でやるしかなさそうだ。最初からそのつもりだったけど。

実行方法

  • hub.exeを絶対パスで指定して実行する
  • hub.exeが存在するパスをカレントディレクトリにして実行する
  • 環境変数に追記してどこからでもexe名だけで実行する

環境変数のPathに追記する

自分で環境変数に追加する(以下のいずれか)。

今回はユーザ環境変数のPathの末尾に追記した。

早速コンソールで実行してみよう。

バージョン

>hub --version
git version 1.9.4.msysgit.1
hub version 2.2.8

ヘルプ

>hub
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty Git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and integrate with another repository or a local branch

   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

'git help -a' and 'git help -g' lists available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

These GitHub commands are provided by hub:

   pull-request   Open a pull request on GitHub
   fork           Make a fork of a remote repository on GitHub and add as remote

   create         Create this repository on GitHub and add GitHub as origin
   browse         Open a GitHub page in the default browser
   compare        Open a compare page on GitHub
   release        List or create releases (beta)
   issue          List or create issues (beta)
   ci-status      Show the CI status of a commit

create

リモートリポジトリを作成するコマンドを発見。ヘルプを見てみる。

>hub create --help
usage: git create [-p] [-d DESCRIPTION] [-h HOMEPAGE] [NAME]

Create a new public GitHub repository from the current git
repository and add remote origin at "git@github.com:USER/REPOSITORY.git";
USER is your GitHub username and REPOSITORY is the current working
directory name. To explicitly name the new repository, pass in NAME,
optionally in ORGANIZATION/NAME form to create under an organization
you're a member of. With -p, create a private repository, and with
-d and -h set the repository's description and homepage URL, respectively.

README.txt

hubを解凍したところにあるREADME.txtを見てみた。

### git create

$ git create
[ repo created on GitHub ]
> git remote add origin git@github.com:YOUR_USER/CURRENT_REPO.git

# with description:
$ git create -d 'It shall be mine, all mine!'

$ git create recipes
[ repo created on GitHub ]
> git remote add origin git@github.com:YOUR_USER/recipes.git

$ git create sinatra/recipes
[ repo created in GitHub organization ]
> git remote add origin git@github.com:sinatra/recipes.git

これ、複数アカウント扱えるのか? これまでgitではgit@github.com.Username1とかにしてたんだけど。 今は放置する。

ローカルリポジトリがない

>hub create
'create' must be run from inside a git repository

console

上記のようなエラーになる。

事前にローカルリポジトリを作成する必要があるらしい。

例のバッチでローカルリポジトリを作成する。pushはまだできないのでコメントアウトしておく。

hubの認証

http://d.hatena.ne.jp/yk5656/20140901/1410702936

こちらにあるように、初回だけユーザ名とパスワードの入力が必要。

はじめてhub createすると求められる。

1
2
3
4

hub create

GitHubサイトへログインし、リモートリポジトリができていることを確認する。

所感

前回と比べると簡単すぎる。楽でいい。

でも、複数アカウントでの使い方や、どこまでの操作ができるかなど、疑問だらけ。 次回は複数アカウントで使う方法を模索する。