2
2

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.

プルリクエストに行き詰まった時にやったこと

Last updated at Posted at 2023-07-25

はじめに

今回はプルリクエストで行き詰まってしまったため自分用の備忘録としても活用できるように作成しました。

ローカルにリポジトリをクローンする

GitHub上に作成したリポジトリをまずはローカル環境にクローンする

% git clone https://github.com/xxx(ユーザー情報)/git_tutorial.git

GitHub上はこれ
イメージ .jpg
以下になればOK
スクリーンショット .jpg

ブランチの作成

次にクローンしてきたリポジトリからプルリクエスト用のブランチを作成する
① クローンしたフォルダに移動

% cd git_tutorial

② ブランチを新規作成

% git checkout -b pull_request

今回はpull_requestというブランチを作成

Switched to a new branch 'pull_request'    

上記の表示があればブランチの作成完了◎

作成したブランチの確認方法
git branchコマンド

ファイルの修正・コミット

① テキストエディタを使用しファイルを修正する
② ファイルを作成した上でコミットする

% git add .
% git commit -m "プルリク用にコミット"

リモートリポジトリにプッシュ

コミットした後は、修正内容をGitHub上のリポジトリに反映させるためプッシュする

% git push origin <作成した新規ブランチ名> (今回はpull_request)

 

プルリクエストの作成

GitHubで作業を進めるためGitHubへ移動しリポジトリを確認
画像のような黄色いメッセージがあればOK
イメージ .jpg
① 赤枠をクリック
ローカルからGitHubへプッシュして画像の赤枠のように「Compare & pull request」のボタンが表示される→クリック

時間が経って表示されなくなってしまったら、「Pull requets」タブの「New pull request」ボタンから作成する

②プルリクエスト作成画面の入力
イメージ.png
赤枠を確認しマージブランチが正しいかを確認する
下にはプルリクエストのコメントと内容を記述する

記載内容
Issue番号や対応内容を記述して、なんの目的でどのように修正したかについて

レビューアを選択

作成したプルリクエストを確認してもらいたい開発者を選択
image.png
赤枠Reviewersの歯車をクリックして対象の開発者を選択する
レビューアーを設定出来たらCreate pull requestボタンをクリックして完了

プルリクエストの確認

画像のようになっていたらOK!!
スクリーンショット .jpg

エラーの対処方法

リモートリポジトリの宛先が設定されていなかった

・エラー文

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

・対応方法

% git remote add origin https://github.com/xxx(ユーザー名)/xxx(リポジトリ名)

一番最初にリモートにアップロードする場合はきちんと宛先を指定しないといけないため設定してから再度pushする

修正を繰り返したためpushできなかった

・エラー文

fatal: remote origin already exists.

・対処方法
originを削除

% git remote rm origin 

その後再度pushを実行

おわりに

最後まで見ていただいてありがとうございました。

参考記事

fatal: remote origin already exists. と表示された場合の解決法

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?