LoginSignup
9
10

More than 3 years have passed since last update.

Xcode + Git:プロジェクト作成後にリモートリポジトリを後から設定する

Last updated at Posted at 2018-09-04

背景

Bitbucketを試したくて、Xcodeでテスト用プロジェクトを作成。
うっかり初期設定でローカルリポジトリを作成してしまった。
Xcode内でリモートリポジトリを後から設定できるのか、少し迷ったのでメモ。

※前提として、リモートリポジトリにはREADME.mdファイルだけ存在する状態

手順

1.ソースコントロールナビゲーターで右クリックして、「Add Existing Remote」
スクリーンショット 2018-09-04 11.00.41.png

2.「Add an existing remote:」
スクリーンショット 2018-09-04 11.09.53.png
「Remote Name」は「origin」が設定されているはず。
「Location」はリモートリポジトリのパスを入力する。

3.ソースコントロールナビゲーター内の「Remotes」ツリーに「origin」が追加される
スクリーンショット 2018-09-04 11.11.09.png

4.Pushすると「The local repository is out of date」で怒られた
スクリーンショット 2018-09-04 11.09.14.png

今考えると、このときの状態はローカルとリモートでコンフリクトが起きている状態なので、
Pushできなくて当然か。

5.「Source Control > Fetch and Refresh Status」する
スクリーンショット 2018-09-04 11.15.27.png

コミットメッセージには以下のような内容が記載される。
「Merge remote-tracking branch 'refs/remotes/origin/master'」

6.最後にPush。問題なければ、リモートリポジトリにはローカルのソースコードが追加されているはず

「Fetch and Refresh Status」は、Xcode9で追加された機能のようだ。

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