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

Git 個人メモ

Last updated at Posted at 2025-05-03

現在のブランチからアップストリーム(上流)ブランチの関連付けを解除する

git branch --unset-upstream

upstreamとは、あなたのローカルブランチが「どのリモートリポジトリのどのブランチ」と連携しているかを定義する関連付けです。

upstreamの確認方法

git branch -vv
# 出力
  develop 4f7bdf9 [origin/develop] cicd.ymlファイルを更新する。
* main    4f7bdf9 [origin/main] cicd.ymlファイルを更新する。
  sub     4f7bdf9 cicd.ymlファイルを更新する。

各ローカルブランチがどのリモートブランチを追跡しているかを確認できます。

リモートリポジトリの参照を削除する

git remote remove origin

リモートリポジトリを確認

git remote -v

originとは、単にローカルGitリポジトリが参照するリモートリポジトリの「別名」です。特別な機能があるわけではなく、単に慣習的に使われる名前です。

Gitリポジトリ移行のプロセス

既存のローカルリポジトリに新しいリモートリポジトリを接続する

git remote add origin git@github.com:oyne2561/ecs-github-actions-learning.git

git branch -M main
git push -u origin main

2個目のGitHubアカウントでSSH接続を設定する方法

  1. 新しいSSHキーペアを生成
ssh-keygen -t ed25519 -C "your-second-email@example.com" -f ~/.ssh/github_second_account
  1. 公開キーを2個目のGitHubアカウントに追加
# 公開キーをクリップボードにコピー
cat ~/.ssh/github_second_account.pub | pbcopy  # Macの場合
# Windowsの場合は: cat ~/.ssh/github_second_account.pub | clip
  1. SSH設定ファイルの編集
vim ~/.ssh/config

設定ファイルに以下のように記述します:

# デフォルトのGitHubアカウント (最初のアカウント)
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_ed25519  # または既存のキーファイル

# 2個目のGitHubアカウント
Host github-second
   HostName github.com
   User git
   IdentityFile ~/.ssh/github_second_account
  1. 設定のテスト
# SSH接続テスト(最初のアカウント)
ssh -T git@github.com

# SSH接続テスト(2個目のアカウント)
ssh -T git@github-second

成功すると、以下のようなメッセージが表示されます:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.
  1. リポジトリのクローンと使用方法
    2個目のアカウントのリポジトリをクローンする場合:
# 通常のURLを変更して使用
git clone git@github-second:username/repository.git

既存のリポジトリのリモートURLを変更する場合:

git remote set-url origin git@github-second:username/repository.git

[初回の場合] リモートリポジトリを設定する

git remote add origin git@github-second:oyne2561/ecs-github-actions-learning.git

github コメント (レビュー)

github_pending.png

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