1
1

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.

親ディレクトリでリポジトリを1つ作り配下の複数ディレクトリでブランチを切って開発を進める方法

Last updated at Posted at 2024-09-26

概要

Udemyなどの教材で不要なリポジトリを増やさずに、親ディレクトリに他人のGitHubリポジトリをクローンし、その中でブランチを切って作業を進める方法です。

※配下の複数ディレクトリは「サブモジュール」として管理しません。

手順

1. 親ディレクトリ(rspec)に移動

bash
cd /home/user/vscode/rspec

2. リポジトリをクローン

bash
git clone https://github.com/他人のユーザー名/リポジトリ名....

# クローンしたディレクトリに移動
cd ディレクトリ名

3. リモートブランチの確認

bash
# ローカルにGitHubリモートから最新の情報を取得
git fetch --all
# リモートとローカル全てのブランチ確認
git branch -a
# -> remotes/origin/main

remotes/origin/main
リモートのmainブランチを追跡していることを意味している。


4. 新しいローカルブランチを作成

リモートの01-firstブランチの内容を基にしてmy_02-secondというローカルブランチが作成される。

bash
git checkout -b my_02-second origin/01-first

捕捉

開発しプッシュするときは切ったブランチ名で
git push origin my_02-second

コミットプッシュする時は、子ディレクトリにリポジトリは作成していないので
リポジトリを作成した親ディレクトリまで移動する。

git checkout -b my_03-third origin/02-second
上記の場合、my_02-second での作業は、my_03-third には影響を与えません

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?