LoginSignup
3
5

More than 5 years have passed since last update.

bitbucketからgithubにプッシュ先を変更する

Last updated at Posted at 2018-12-14

12/13 bitbucketからgithubにプッシュ先を変更する

bitbucketを使っていたが、githubに変えたかったのでメモ。

初めてgitのリポジトリにpushする時は、先にssh-keyの設定が必要です。

例えば、railsチュートリアルでずっとbitbucketを使っていたが、githubに変えたい時など。

(githubにアカウント登録済である前提で進めます)

まずgithubログイン後、右上のアカウントメニューから、your repository→clone or downloadでプッシュしたいリポジトリのURLを確認

(ssh接続のURL)
git@github.com:xxxxxxxxxアカウント名/リポジトリ名.git

プッシュ先を変更する前に、現在のプッシュ先を確認

git remote -v

その後以下のコマンドを入力

git remote set-url origin gitのリポジトリURL

もし初回でremoteを追加する必要があればadd

git remote add origin gitのリポジトリURL

その後pushするも、まだSSH接続出来ていないとのエラーが出ます。

The authenticity of host 'github.com ('000,444,612,113)' can't be established.
RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
RSA key fingerprint is MD5:1111111111111111111111111111111111111
Are you sure you want to continue connecting (yes/no)?←ここはyesと入力

まずSSH接続の設定をするため、ターミナルでsshキーを表示するコマンドを入力。

cat ~/.ssh/id_rsa.pub

以下のように表示されるので、メールアドレス以外を全てコピーし、gitのsshキーを設定する。

ssh-rsa
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkkkkkkkkkkkkkkkkkkkkkkkkkkoooihuihoafoihaounofijpihjoifehkjonnoiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiihhhhhhhhhhhhhhhhhsssssssssssssssskkkkkkkdddddddddddddddkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

もし表示されなければ、以下のコマンドで新しくsshキーを作成します。

ssh-keygen

その後、公開鍵を表示します。

cat ~/.ssh/id_rsa.pub

sshキーの設定場所は、
githubログイン後、右上のsetting→ssh and gpg key→new ssh keyを選択

コピーした公開鍵を貼り付けし、ADDsshkeyを押すと公開鍵が追加される。

最後に、ターミナルで以下のコマンドを打ち、ssh接続出来ているか確認する。

ssh -T git@github.com

下記のメッセージが表示されればSSH接続完了です!

Hi 〇〇〇アカウント名 You've successfully authenticated, but GitHub does not provide shell access.

もう一度

git push origin master

でgitのリポジトリにプッシュ出来ました!

もし、

git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com
https://qiita.com/tesoro/items/af4a80b7ebb9ad34e5fd

というエラーが出たらmasterブランチがないということなので、

git init
git add -A
git commit -m "First commit"
git push origin master

でpush出来ました!

(参考1)[https://qiita.com/muneo/items/1321bf8cdb21178a73e2]

(参考2)[https://qiita.com/tesoro/items/af4a80b7ebb9ad34e5fd]

3
5
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
3
5