ローカルで作成(git init)したリポジトリをリモートへ登録する手順🔗

ローカルで作成(git init)したリポジトリを GitHub や Bitbucket へ登録する手順について記載します。

 

git init 済みのローカルリポジトリがある状態から開始する場合、

  1. remote (GitHub / Bitbucket) 側に空のリポジトリを作成
  2. remote を登録: git remote add origin <URL>
  3. remote を確認: git remote -v
  4.  push

という流れです。GitHub 公式でも git remote add origin <URL> → git remote -v という方法が案内されています。

 

 

 

 


 

1. ローカル側を確認 🔗

すでに以下まで完了しているものとします。

cd ~/path/to/project
git init

 

最初に現在の状態を確認します。

git status 
git branch

 

まだコミットしていなければ 以下を実行します。

# 実際のファイル名へ変更して以下を実行 (コミットするファイルをすべて指定)
git add README.md
# まだコミットない場合に以下を実行
git commit -m "Initial commit"

 

ブランチ名を main に統一したいなら、以下を実行しておくとわかりやすいです。

git branch -m main

 

 


 

2. Remote 側に空のリポジトリを作る 🔗

GitHub などの Remote で新しいリポジトリを作成します。

 

NOTE

ローカル側にすでに README.md, LICENSE, .gitignore などが存在する場合、リモート側でこれらファイルを追加せず、空のリポジトリとして作成すると良いです。

 

 


 

3. Remote を origin として登録 🔗

GitHub を例に Remote を origin として登録する手順を記載します。

SSH を使うなら、以下のコマンドを入力します。

git remote add origin git@github.com:<username>/<repository-name>.git

HTTPS を使うなら、以下のコマンドを入力します。

git remote add origin https://github.com/<username>/<repository-name>.git

 

登録確認は、以下のコマンドを実行します。

git remote -v

以下のような出力をしてくれて確認できます。

origin  git@github.com:kinoshita-hidetoshi/Programing-Items.git (fetch)
origin  git@github.com:kinoshita-hidetoshi/Programing-Items.git (push)

 

この origin は単なるリモートリポジトリの別名です。GitHub 公式でもこの方法が説明されています。

 

 


 

4. 最初の push 🔗

最初の push を行います。

git push -u origin main

 

これで以下のような関係になります。

Local:
main
│
│ git push
▼
Remote:
origin/main

 

-u (--set-upstream) によってローカル main と origin/main の追跡関係が設定されるので、以降は基本的に下記だけでOKです。

git push

 

 


 

origin already exists が出た場合 🔗

既に origin が存在すると、

fatal: remote origin already exists

になります。

URL を変更するだけなら下記のような感じで origin を変更します。

git remote set-url origin git@github.com:USER/NEW-REPO.git

 

 


 

結局、最小限これだけ 🔗

結局、既存ローカルリポジトリを GitHub へ上げるだけなら以下のような感じになります。

cd project

git status

# 実際のファイル名へ変更して以下を実行 (コミットするファイルをすべて指定)
git add README.md
# まだコミットない場合に以下を実行
git commit -m "Initial commit"

# 現在のブランチを main に改名する場合のみ実行。すでに main なら不要
git branch -m main

git remote add origin git@github.com:USER/REPOSITORY.git

git remote -v

git push -u origin main

 

 


 

ライセンス 🔗

本ページの情報は、特記無い限り下記 MIT ライセンスで提供されます。

The MIT License (MIT)

  Copyright 2026 Kinoshita Hidetoshi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 

 

参考 🔗

 


 

変更履歴 🔗

2026-09-25 - 新規作成

 

Programming Items トップページ

プライバシーポリシー