LoginSignup
0
1

More than 3 years have passed since last update.

GitHubの既存リポジトリにローカルで作成したプロジェクトを移植する

Last updated at Posted at 2021-01-17

諸事情により、GitHubの既存のリポジトリにローカルで作成したプロジェクトを移植しないといけないという経験をしたのでここにアウトプット

流れはGitの初期化と同じ感じに

移植作業といっても、既存のリポジトリに初期化したプロジェクトをpushするのと同じ流れになるから普通に初期化の流れをやってみる。

$ git remote -v  // remoteのURLがないか確認
$ rm -rf .git  // remoteのURLがあったら実行
$ git init
$ git add .
$ git commit -a -m "新プロジェクトの移植作業"
$ git remote add origin git@github.com:管理ユーザー名/移植したいリポジトリ名.git
$ git push -u origin main -f  // 強制的にpushを実行

これで処理を実行すると、以下のようなエラーが発生。

error: src refspec main does not match any
error: failed to push some refs to 'git@github.com:管理ユーザー名/移植したいリポジトリ名.git

エラーが出たからとりあえずググる。

この記事 ( https://qiita.com/fukkatsu3/items/c488ec9559f6cca34313 ) を参考に確認してみると、

$ git branch
* master

mainブランチに移植したいのにmasterブランチの状態だったことを確認。

$ git push -u origin HEAD:main

記事をそのまま参考にしてやってみた。

$ git push origin HEAD:main
To github.com:管理ユーザー名/移植したいリポジトリ名.git
 ! [rejected]        HEAD -> main (fetch first)
error: failed to push some refs to 'git@github.com:管理ユーザー名/移植したいリポジトリ名.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

依存関係とか諸々でpushを拒絶した模様。

今回は思考停止で上書きしてもよかったから、強制的にpushを実行。

$ git push -u origin HEAD:main -f

これでできた。

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