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?

More than 1 year has passed since last update.

備忘:ローカルで作成したフォルダを後からGitおよびGithubに登録する(Windows)

0
Posted at

ローカルで作成したフォルダを後からGitおよびGithubに登録する(Windows)

  • 既にPC内に存在しているフォルダを、既に存在している中央リポジトリ(githubサーバー)を、SourceTreeで紐づける場合の手順です
  • 【注意】かなり独自のやり方で無理矢理感があるので正しい公式なやり方ではないと思う

手順


【1】 SourceTreeを起動します


【2】 画面上部の「ファイル」メニューの「新規/クローンを作成する」を選択
image.png


【3】 画面上部の「+」ボタンをクリックします
image.png


【4】「Create a repository」の画面で以下の内容を入力して、「作成」ボタンをクリックします
- 保存先のパス:既にPC内に存在しているフォルダを選択
- 名前:↑を入力すると自動で入ります
- プルダウンはGitを選択
- 次のアカウントでリポジトリを作成はチェックを入れない
image.png


【5】 以下のような警告は、「はい」を選択します
image.png


【6】 未コミットのファイルやフォルダがある場合はここでPushはせずにコミットだけしておく。するとmasterにコミットされた状態となる


【7】 次の画面の右上の「リモート」を選択します
image.png


【8】 表示された以下のダイアログで、「設定」を選択します
image.png


【9】 次に表示されたモーダル画面の左下の「追加」ボタンを押下します
image.png


【10】 次に表示されたリモートの詳細設定画面で以下の内容を入力して、「OK」ボタンをクリックします
image.png

  • 必要な情報
    • リモート名:origin
    • デフォルトリモートのチェックをON
    • URL/パス:既に存在している中央リポジトリ(githubサーバー)のURL(.gitまでのパス)
  • 外部サービスとの拡張統合オプション
    • Remote Account
      • Generic Accountを選択
    • Legacy Account Settings
      • ホストタイプ:Github
      • ルートURL:そのままでOK
      • ユーザ名:自分のGithubユーザ名

【11】 元のリポジトリ設定のモーダル画面も、「OK」ボタンを押下して閉じます
image.png


【12】 左ペインのリモート>originを右クリックして、「originからフェッチ」を選択
image.png


【13】 左ペインのリモート>origin>mainを右クリックして、「origin/mainをチェックアウト」を選択
image.png


【14】 チェックアウトのモーダル画面で、以下の入力値を確認(基本デフォルトのままでいいはず)してOKを選択する
image.png

  • チェックアウトするリモートブランチ:
    • 既に存在している中央リポジトリ(githubサーバー)側のチェックアウトしたいブランチを選択
      • mainとか、masterとか、develop
  • 新ブランチ名
    • ローカル側のブランチ名
      • 原則リモートと同じでOK
  • ローカルブランチでリモートブランチを追跡するのチェックはON

【15】カレントをmainブランチ(リモートから落としてきたブランチ)にした状態で、右上のターミナルを開く。
image.png


【16】 以下のコマンドを手動で実行

実行前に3wayマージできるツールを「ツール>オプション>Diffタブ」で設定しておくとよい

例:masterブランチを現在のブランチにマージする場合

git merge master --allow-unrelated-histories

あるいは、リモートのmasterをpullする場合

git pull origin master --allow-unrelated-histories

ここで以下のように競合する場合は、その後はGUI上でマージ操作をする

$ git merge master --allow-unrelated-histories
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

正しくマージされると以下のように、親の違うツリーが1つにマージされる

$ git merge master --allow-unrelated-histories
Merge made by the 'recursive' strategy.
 sample.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 sample.txt

image.png


【17】 あとは普通に使うだけ

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?