9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Git】別リポジトリにpushする

Posted at

cloneしたリポジトリとは別のリポジトリにpushしたいとき
そのままpushしようとすると下記のようなエラーになる

! [remote rejected] master -> master (shallow update not allowed)
error: failed to push some refs to 'git@github.com:{別のリポジトリ名}'

1. 履歴が空のブランチ(orphan branch)を作成する

git checkout --orphan tmp

2. 履歴が空のブランチにコミットを作成する

git commit

3. 空のブランチからmasterブランチを作成する

git checkout -b master

4. pushするリモートブランチを設定する

git remote add origin {別のリモートブランチURL}

5.リモートブランチへpushする

git push origin master

これで無事pushできた!

commit履歴を一旦空にすることで新しいリポジトリにpushすることができた!
(リモートブランチにないコミット履歴が入っていたから怒られた?わかったら追記:writing_hand:

参考にさせていただいた記事

9
6
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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?