1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

コマンドでgithubにリポジトリ作成

Posted at

はじめに

エディタのターミナル上でGitHubリポジトリを作成してpushする方法をまとめます

前提条件

GitHub CLIのインストール確認

# バージョンを確認
gh --version

GitHub認証

# GitHubで認証
gh auth login

GitHub CLIをインストールしていない場合は公式ドキュメントから適切なOSのインストール方法を確認してください

コマンド

# 1. プロジェクトディレクトリに移動
cd /path/to/your/project

# 2. Gitリポジトリ初期化
git init

# 3. ファイルをステージング
git add .

# 4. 初回コミット
git commit -m "Initial commit"

# 5. GitHubリポジトリ作成してpush
gh repo create <リポジトリ名> --public --source=. --remote=origin --push

主なオプション

  • --public: 公開リポジトリとして作成
  • --private: プライベートリポジトリとして作成
  • --source=.: 現在のディレクトリをソースに指定
  • --remote=origin: リモート名をoriginに設定
  • --push: 作成後に自動でpush

デフォルトブランチをmainに設定

# デフォルトブランチをmainに変更
git config --global init.defaultBranch main

# 設定内容を確認
git config --list | grep defaultbranch
# 出力例:init.defaultbranch=main

まとめ

  • gh repo createコマンド1つでリポジトリ作成・リモート追加・pushが完了
  • 従来必要だったgit remote addgit push -u origin mainが不要
  • オプションで公開/非公開やブランチ名を柔軟に設定可能

さいごに

GitHub CLIを使うことで、ブラウザを開くことなくターミナルから直接GitHubリポジトリを作成できました。

参考サイト

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?