GitHub for Beginners:よくある質問への回答
GitHub Blog は、初心者向けに SSH キーの生成と GitHub への登録手順を解説する最終エピソードで、セキュリティ認証の実践的ガイドを提供している。
キーポイント
SSH キーの仕組みと重要性
公開鍵と秘密鍵のペア構成について説明し、GitHub へのコードプッシュ時に本人確認(認証)に使用されるセキュリティ基盤としての役割を解説している。
ターミナルでのキー生成手順
ssh-keygen コマンドを使用して ed25519 アルゴリズムの鍵ペアを作成し、パスフレーズを設定して保存する具体的なコマンド例を示している。
ssh-agent の設定と管理
パスワード入力を頻繁に行う必要を減らすため、作成した秘密鍵を ssh-agent に追加し、安全に記憶させる手順を案内している。
GitHub への公開鍵登録プロセス
ターミナルで生成された公開鍵をコピーし、GitHub の設定画面から SSH キーとして登録する UI を介した完了手順を詳細に説明している。
PAT の種類と管理
GitHub では細粒度トークン(fine-grained)とクラシックトークンの2種類があり、それぞれに異なる権限設定が可能です。
トークンの生成と保管
トークンを発行する際は用途や有効期限を明確にし、GitHub 側で一度しか表示されないため、必ずパスワードマネージャーなどに保存する必要があります。
トークンの生成と管理
有効期限とスコープを設定してトークンを生成し、GitHub は一度だけ表示するため、パスワードマネージャーなどに安全に保存する必要があります。
影響分析・編集コメントを表示
影響分析
この記事は、AI や高度な技術分野における開発者にとって必須となるバージョン管理ツール(Git)の基礎的なセキュリティ設定を解説しており、新規参入者が安全に開発環境を構築するための重要な指針となっている。特に SSH キー管理の誤解やミスがプロジェクトのセキュリティリスクにつながる可能性があるため、初心者向けの明確な手順提示は実務現場でのインシデント防止に寄与する。
編集コメント
このコンテンツは特定の AI 技術の革新や業界動向を報じるものではなく、開発ツールの基礎的なセットアップ手順に焦点を当てた教育資料です。そのため、AI 関連企業への言及はなく、重要性スコアも実用性の高い入門記事として低めに設定されています。
GitHub for Beginners へようこそ。今回は今シーズンの最終回であり、これまで多くのトピックを取り上げてきました。他のエピソードもぜひチェックして、私たちが議論したさまざまなトピックをご覧ください。
今日は、特に初心者の方が抱きやすい疑問にお答えする時間を設けます。それでは早速始めましょう。
いつも通り、動画をご覧になりたい場合や参照したい場合は、YouTube で「GitHub for Beginners」のエピソードをすべてご覧いただけます。
SSH とは何か、また SSH キーを GitHub に追加する方法は?
SSH キーとは、セキュアシェル(Secure Shell)キーのことです。これはお使いのコンピュータ上の 2 つのファイルからなるペアで、秘密鍵と公開鍵という 2 つの部分を持っています。
秘密鍵はあなたのコンピュータ上にのみ保存され、決して共有してはいけません。一方、公開鍵は GitHub のようなプラットフォームに共有するものです。公開鍵を GitHub に登録すると、git はコードのプッシュやプルを行う際に、あなたの秘密鍵を使って身元を確認します。認証を受けるためには、GitHub 上の公開鍵が、お使いのコンピュータ上の秘密鍵と一致している必要があります。
では、どのようにすればよいのでしょうか?それでは今すぐキーペアを作成し、公開鍵を GitHub に追加してみましょう。
(なお、動画による手順解説も用意されていますので、そちらをご希望の場合はご覧ください。)
ターミナルを開き、以下のコマンドを入力してください。メールアドレスのプレースホルダーは、GitHub にログインする際に使用するあなたのメールアドレスに置き換えてください。
ssh-keygen –t ed25519 – C YOUREMAIL@DOMAIN.COM
ファイル名と保存場所を指定するプロンプトが表示されたら、デフォルトのファイルと場所を受け入れるために Enter キーを押してください。
記憶しておけるパスフレーズを入力してください。なお、ターミナルには入力した内容が表示されないため、誤字がないよう注意してください!
パスフレーズを再入力してください。
これで新しい SSH キーが作成されます。次に、このキーを ssh-agent に追加する必要があります。ssh-agent は、パスフレーズの入力を繰り返さなくて済むように、安全にキーを保存するプログラムです。
⟦CODE_0⟧
詳細については、SSH キーを ssh-agent に追加する方法に関するドキュメントをご覧ください。
⟦CODE_1⟧
この新しい SSH キーを ssh-agent に追加するには、以下のコマンドを実行してください。プロンプトが表示されたらパスフレーズを入力する必要があります。
ssh-add ~/.ssh/id_ed25519
SSH キーの作成と ssh-agent の設定が完了したので、次のステップは公開キーを GitHub に追加することです。
ターミナルで以下のコマンドを実行してください。
cat ~/.ssh/id_ed25519.pub
そのコマンドに対する応答としてターミナルに表示された行全体をコピーしてください。
ブラウザを開き、github.com へ移動します。
右上隅にあるプロフィール画像をクリックし、「Settings」を選択します。
左側のメニューから「SSH and GPG keys」を選択します。
右側にある緑色の「New SSH key」ボタンをクリックします。
追加しようとしているキーに、自分が覚えておけるような説明を含む名前を「Title」ボックスに入力してください。例えば、これが業務用のラップトップである場合は、「work-laptop」というタイトルを入力すると良いでしょう。
ターミナルからコピーしたキーを「Key」ボックスに貼り付けます。
ウィンドウ下部にある緑色の「Add SSH key」ボタンをクリックしてください。
おめでとうございます!これでコンピュータが SSH を介して GitHub に接続できるよう設定されました。
PAT を GitHub に追加するにはどうすればよいですか?PAT とは何ですか?
PAT は Personal Access Token の略です。PAT は、認証を必要とするツールのために GitHub で作成する特別な資格情報です。その権限はあなたが管理でき、いつでも取り消すことができます。GitHub では、コマンドラインまたは GitHub API を介して認証を行う際に PAT をよく使用します。
利用可能な PAT には 2 つの種類があります:ファイングレーナートークンとクラシックトークンです。まずはファイングレーナートークンの作成手順を説明します。
ブラウザを開き、github.com にアクセスしてください。
右上隅にあるプロフィールアイコンをクリックし、「Settings」を選択してください。
左側の列のオプションリストの一番下までスクロールし、「Developer settings」を選択してください。
左側の列で「Personal access tokens」のオプションを展開し、表示されたオプションから「Fine-grained tokens」を選択してください。
ウィンドウ中央にある緑色の「Generate new token」ボタンをクリックしてください。
トークンの名前と説明を入力してください。これにより、そのトークンが何に使用されるかが明確になるようにします(例:名前は"cli-access"、説明は"Copilot CLI にアクセスする"など)。
「Expiration」の下で、トークンを有効にしておく必要がある期間に一致する日付を選択してください。一度期限が切れると、トークンはもはや機能しなくなります。
「リポジトリアクセス」の下で、PAT がアクセスできるようにするリポジトリを選択します。どのリポジトリにアクセスする必要があるか分かっている場合は、特定のみに制限することも可能です。
「権限」の下で、「権限の追加」をクリックし、この PAT に付与する権限を選択します。これにより、PAT が実行できる範囲を定義できます。
各権限について、読み取り専用アクセスとするか、読み取りおよび書き込みアクセスとするかを指定できます。
権限に満足したら、スクロールして下部にある緑色の「トークンを生成」ボタンをクリックします。
ウィンドウが表示され、このトークンに関連するすべての情報のレビューが提供されます。情報が正しいことを確認した後、「トークンを生成」をクリックします。
GitHub は now トークンを表示します。必ずコピーして安全な場所(例:パスワードマネージャー)に保存してください。GitHub はこのトークンを一度だけ表示するためです。
詳細については、Personal Access Tokens に関するドキュメントをご覧ください。
次に、クラシックトークンの作成手順を確認しましょう。ご覧の通り、いくつかの点で非常に似ています。
ブラウザを開き、github.com に移動します。
右上隅のプロフィールアイコンをクリックし、「設定」を選択します。
左側の列にあるオプションリストの下部にスクロールし、「開発者設定」を選択します。
左側の列で「Personal access tokens」オプションを展開し、表示されたオプションから「Tokens (classic)」を選択します。
メインウィンドウで「Generate new token」をクリックし、「Generate new token (classic)」を選択してください。
トークンには、その用途を明確に示す名前(例:"terminal-access")を付けてください。
「Expiration」の下で、トークンを有効にする必要がある期間に一致する日付を選択してください。期限が切れると、トークンはもはや機能しなくなります。
トークンのスコープを選択してください。スコープは、そのトークンが付与するアクセス権限を示します。
スコープに満足したら、スクロールして下部にある緑色の「Generate token」ボタンをクリックしてください。
GitHub は現在、トークンを表示します。必ずコピーして安全な場所(例:パスワードマネージャー)に保存してください。なぜなら、GitHub はこのトークンを一度だけしか表示しないからです。
これでクラシックトークンが作成されます。次回、ターミナルで GitHub がパスワードを求めた際、パスワードを入力する代わりに、このトークンを貼り付けることができます。
マージとリベースの違いは何ですか?また、マージ競合はどうやって解決すればよいですか?
マージ競合とは、2 つの変更がファイルの同じ部分を触ったときに発生し、git が最終バージョンを決定するためにあなたの助けを必要とする状態のことです。これを解決する方法はいくつかありますが、ここでは GitHub の UI を使用して手順を追って説明します。
マージ競合が発生しているプルリクエストを開いてください。GitHub は競合があることを示すメッセージを表示し、自動的にマージできない旨を伝えます。
スクロールして下部にある、競合に関する警告内にある「Resolve conflicts」ボタンをクリックしてください。
GitHub は競合が発生しているファイルを開きます。エディタを使用して、各競合のケースで使用するファイルのバージョンを選択することで、競合を解決してください。
ファイルに競合マーカーがもはや表示されなくなったら(つまり、すべての競合に対処した場合)、右上隅にある「Mark as resolved(解決済みとしてマーク)」を選択します。
このプロセスは、マージ競合が発生しているすべてのファイルに対して繰り返してください。
競合のあるすべてのファイルに対処した後、ウィンドウ上部の緑色の「Commit merge」ボタンをクリックします。
これにより、マージされた競合を含むプルリクエストが更新され、その変更をリポジトリにマージできるようになります。お疲れ様でした!
次に、マージとリベースの違いについて、またどちらをいつ使用すべきかについてお話しましょう。
マージは、両方の履歴を結びつける新しいコミットを作成することで、あるブランチの変更点を別のブランチに結合します。これは両方のブランチの履歴を保持します。作業がどのように行われたかの完全な履歴を保持したい場合にマージを行うべきです。これは、メインブランチにマージされる予定の機能ブランチ(例えば、新しい機能を追加する場合など)で一般的に使用されます。
一方、rebase(リベース)は、ブランチのコミットを別のブランチの上に移動または置き換える操作です。これにより履歴が書き換えられ、線形かつクリーンなコミットのタイムラインが作成されます。機能ブランチを main ブランチから最新の変更を取り込んで更新する際など、クリーンで線形の履歴を残したい場合に rebase を行うべきです。
直前のコミットを元に戻すにはどうすればよいですか?
すでにコミットをブランチにプッシュした状態で、それを元に戻したい状況にあるとしましょう。GitHub の UI を通じてコミットを元に戻すことができます。
github.com で元に戻したいコミットを開きます。
そのコミットのページを下へスクロールし、「Revert(リバート)」ボタンを選択します。
GitHub は、前回のコミットでの変更を取り消す新しいコミットを作成します。重要なのは、この操作がコミット履歴を消去するのではなく、前回の取り消し変更を無効にする新たな変更を追加する点です。その後、このコミットを直接マージするか、プルリクエストとして作成することができます。他の人がそのブランチを使用している可能性がある場合は、プルリクエストを作成するのが最も安全な選択肢です。
もし変更がローカル環境のみで、まだブランチにプッシュしていない場合、以下のコマンドを実行してローカルでコミットを元に戻すことができます。
git reset --soft HEAD~1
これによりコミットはローカルリポジトリから削除されますが、変更点はステージングされた状態のまま保持されるため、変更を失うことはありません。もしローカル環境も含めて変更を元に戻し、ワークスペースをリセットしたい場合は、以下のコマンドを使用できます。ただし、この操作を行うと作業内容が失われる可能性がある点にご注意ください。
git reset --hard HEAD~1
GitHub でフォークされたリポジトリを更新または同期するにはどうすればよいですか?
リポジトリをフォークすると、プロジェクトの独自のコピーが作成され、元のリポジトリに影響を与えることなく、その内容を探索したり変更を加えたりできるようになります。これはオープンソースプロジェクトに貢献したい場合に特に重要です。以下にリポジトリをフォークする方法を示します。
github.com でフォークしたいリポジトリを開きます。
リポジトリの上部にある「Fork」ボタンを選択します。
このフォーク版の所有者(Owner)を選択します。多くの場合、これはあなたの GitHub アカウントになります。
必要に応じて新しいリポジトリ名を入力して名前を変更することもできます。デフォルトでは、フォークされたリポジトリはアップストリームリポジトリと同じ名前を保持します。
ウィンドウの下部にある「Create fork」を選択します。
これにより、プロジェクトがあなたのアカウントの下に完全なコピーとして作成されます。ローカルで作業するには、「Code」ボタンを選択してマシンにクローンしてください。
フォークの詳細については、ドキュメントをご覧ください。
フォークを作成した後、アップストリームリポジトリから最新の変更を常に取得していることを確認する必要があります。そうしないと、フォークされたコピーはすぐに古くなってしまいます。
github.com でフォークしたリポジトリのメインページに移動します。
リポジトリの上部にある「Sync fork」ボタンを選択します。
ポップアップメニューから「Update branch」を選択します。
これを行うと、GitHub が自動的にアップストリームリポジトリからの最新の変更を取得し、フォークを最新の状態に保ちます。コマンドラインからも同様の操作が可能です。
ターミナルを開き、リポジトリのディレクトリに移動します。
アップストリームリポジトリを設定します。以下のコマンド内の URL は、元のリポジトリの URL に更新してください。
git remote add upstream YOUR_ORIGINAL_REPOSITORY_URL
最新の変更を取得します。
git fetch upstream
最新の変更をプロジェクトにマージします。なお、以下のコマンドではアップストリームプロジェクトがデフォルトブランチとして main を使用していると仮定しています。異なるブランチを使用している場合は、以下のコマンドでそのブランチ名を指定する必要があります。
git merge upstream/main
これにより、ローカルコピーがアップストリームブランチのすべての変更で更新されます。次に、リポジトリを同期させるために GitHub へプッシュする必要があります。
git push origin main
これで、プロジェクトのコピー上で作業し、作業内容を同期する方法がわかりました!
GitHub でプルリクエスト(Pull Request)をレビューするにはどうすればよいですか?
プルリクエスト(PR と略されることが多い)は、コードを共有し変更について議論するための場所です。プルリクエストをレビューする際に心に留めておくべき、役立つ実践方法が 3 つあります。
まず、プルリクエストの目的を理解することから始めましょう。プルリクエストを開いて説明を読み、関連する課題(issue)やスクリーンショット、著者からのメモがないか確認します。目的を知ることで、なぜ変更が行われたのか、何を注目すべきかが明確になります。
コードの変更は小さなセクションごとにレビューしましょう。「Files changed」タブを開き、変更をグループ単位で一つずつ確認していきます。不明な点があれば、その行にコメントを残してください。質問をしたり、提案をしたり、より良いアプローチがある場合は著者に伝えましょう。コメントは具体的にし、何を指しているのかが明確になるようにします。コマンドラインまたはコードスペース(codespace)で自分のマシン上でコードを実行して理解を深めるのも有効です。プルリクエストのマージに必須ではない提案の場合は、「nit」といった用語を使いましょう。
うまくいっている点を強調しましょう。整理された考え深い、あるいは自分にとって学びになるコードを見つけたら、ぜひ言及してください!ポジティブなフィードバックは良いパターンを強化し、チームメンバーがサポートされていると感じさせるのに役立ちます。
プルリクエストのレビュー方法については、当社のトピックに関するドキュメントをご覧ください。
すべてが準備ができたと感じたら、「Submit review」ボタンを使用して変更を承認するか、更新を要求してください。
Copilot のコードレビュー機能は、プルリクエストの理解を深め、改善点を提案するのにも役立ちます。なお、Copilot を利用するには、組織管理者がリポジトリまたはユーザーアカウントに対して Copilot を有効化する必要があります。一度 Copilot が有効化されると、特別なインストールは不要で、Copilot のコードレビューはプルリクエストのオプションとして自動的に表示されます。
Copilot のコードレビューを利用したい場所で、github.com 上でプルリクエストを開きます。
右上にある「Reviewers」を選択します。
提案されたレビュアーの一覧から「Copilot」を選択します。
短時間で Copilot がレビューを完了します。下にスクロールすると、Copilot が残したコメントを確認できます。Copilot は常に「Comment(コメント)」タイプのレビューを残し、「Approve(承認)」や「Request changes(変更要求)」タイプのレビューは行いません。これは、Copilot のレビューが必須承認数にカウントされず、変更のマージをブロックしないことを意味します。
🔍 Copilot のコードレビューに関する詳細は、当社の Copilot コードレビュードキュメントをご覧ください。
次のステップ
これで完結です!今回のエピソードをもって、「GitHub for Beginners」シリーズの別のシーズンが終了しました。ここでは、私たちが目撃したり聞いたりした最も一般的な質問への回答を取り上げました。この情報が皆様のお役に立てたことを願っています。また、当社の「GitHub for Beginners」トピックの完全なライブラリーもぜひご覧ください。
Happy coding!(楽しいコーディングを!)
本記事「GitHub for Beginners: Answers to some common questions」は、The GitHub Blog で最初に公開されました。
原文を表示
Welcome back to GitHub for Beginners. This is the final episode of the season, and we’ve covered a lot so far. Make sure to check out our other episodes to see all the various topics we’ve discussed.
Today, we’re going to spend some time answering some questions that people often have, especially when they’re first getting started. So without further ado, let’s jump right in.
As always, if you prefer to watch the video or want to reference it, we have all of our GitHub for Beginners episodes available on YouTube.
What is SSH and how do I add my SSH key to GitHub?
An SSH key is a secure shell key. It’s a pair of files on your computer that has two parts: a private key and a public key.
The private key stays on your computer and should never be shared. The public key is what you share with platforms like GitHub. When you store your public key on GitHub, git uses your private key to confirm your identity when you push and pull code. In order for you to be authenticated, your public key on GitHub needs to match the private key on your computer.
So how do you do this? Let’s create a key pair and add your public key to GitHub now.
(And remember, if you prefer a video walkthrough, that is available.)
Open up a terminal and enter the following command. Remember to replace the email placeholder with your email address you use to log into GitHub.
ssh-keygen –t ed25519 – C YOUREMAIL@DOMAIN.COM
When it prompts you to enter a file to save the key, press Enter to accept the default file and location.
Enter a passphrase that you’ll remember. Note that the terminal will not display what you type, so be careful not to have any typos!
Reenter your passphrase.
This will create your new SSH key. Now you want to add it to your ssh-agent. An ssh-agent is a program that securely stores your keys so that you don’t need to keep entering your passphrase.
To learn more, check out our docs about adding your SSH key to ssh-agent.
To add this new SSH key to the ssh-agent, run the following command. Note that you will need to add your passphrase when prompted.
ssh-add ~/.ssh/id_ed25519
Now that you have created the SSH key and configured your ssh-agent, the next step is adding the public key to GitHub.
In your terminal, run the following command.
cat ~/.ssh/id_ed25519.pub
Copy the entire line that appears in the terminal as a response to that command.
Open a browser and navigate to github.com.
Click your profile picture in the top-right corner and select Settings.
In the menu on the left-hand side, select SSH and GPG keys.
On the right-hand side, click the green New SSH key button.
Give the key that you’re about to add a name in the “Title” box that describes this key in a way you’ll remember. For example, if this is your work laptop you might enter a title of “work-laptop”.
Paste the key you copied from the terminal into the “Key” box.
Click the green Add SSH key button at the bottom of the window.
Congratulations! Your computer is now configured to connect to GitHub over SSH.
How do I add a PAT to GitHub? What is a PAT?
PAT stands for Personal Access Token. A PAT is a special credential that you create on GitHub for tools that need authentication. You control its permissions and can revoke it any time. On GitHub, you’ll commonly use a PAT to authenticate via command line or the GitHub API.
There are two types of PATs available: fine-grained tokens and classic tokens. First we’ll walk through creating a fine-grained PAT.
Open a browser and navigate to github.com.
Click your profile picture in the top-right corner and select Settings.
Scroll to the bottom of the list of options in the left-hand column and select Developer settings.
In the left-hand column, expand the option for Personal access tokens. Select Fine-grained tokens from the options displayed.
Click the green Generate new token button in the center of the window.
Enter a name and description for the token. This should make it clear what the token is going to be used for (e.g., a name of “cli-access” with a description of “access the Copilot CLI”).
Under “Expiration,” select a date that matches how long you need the token to be valid. Once the token expires, it will not work anymore.
Under “Repository access,” select which repositories you want the PAT to be able to access. You can limit the selection to only specific repositories if you know which repositories it will need to access.
Under “Permissions”, click Add permissions to select which permissions you’re granting to this PAT. This lets you define the scope of what the PAT can do.
For each permission, you can specify whether it has read-only access or read and write access.
When you’re satisfied with the permissions, scroll to the bottom and click the green Generate token button.
A window pops up, providing a review of all of the information associated with this token. Verify that the information is correct, and then click Generate token.
GitHub will now show you the token. Make sure that you copy it and store it in a safe location (e.g., a password manager), because GitHub only shows you this token once.
For more information, check out our documentation about Personal Access Tokens.
Now let’s go through creating a classic token. As you’ll see, it’s very similar in several ways.
Open a browser and navigate to github.com.
Click your profile picture in the top-right corner and select Settings.
Scroll to the bottom of the list of options in the left-hand column and select Developer settings.
In the left-hand column, expand the option for Personal access tokens. Select Tokens (classic) from the options displayed.
In the main window, click Generate new token and select Generate new token (classic).
Give the token a clear name that explains what it will be used for (e.g., “terminal-access”).
Under “Expiration,” select a date that matches how long you need the token to be valid. Once the token expires, it will not work anymore.
Select the scopes for your token. The scopes indicate what access permissions the token grants.
When you’re satisfied with the scopes, scroll to the bottom and click the green Generate token button.
GitHub will now show you the token. Make sure that you copy it and store it in a safe location (e.g., a password manager), because GitHub only shows you this token once.
This creates the classic token. The next time that GitHub asks for your password in a terminal, instead of supplying your password, you could paste this token.
What’s the difference between merging and rebasing, and how do I fix a merge conflict?
A merge conflict is what happens when two changes touch the same part of a file, and git needs your help to decide what the final version should be. There are a few different ways you can resolve this, but we’re just going to walk through it using the GitHub UI.
Open a pull request that has a merge conflict. GitHub will provide a message indicating that there’s a conflict and you won’t be able to automatically merge.
Scroll to the bottom and click the Resolve conflicts button inside the warning about conflicts.
GitHub opens the files that have conflicts. Use the editor to resolve the conflicts by choosing which version of the file to use in each case where there’s a conflict.
Once the file has no more conflict markers (i.e., you’ve addressed every conflict), select Mark as resolved in the top-right.
Repeat this process for every file that has merge conflicts.
After you’ve addressed all the files that have conflicts, click the green Commit merge button at the top of the window.
This updates your pull request with the merged conflict and now you’ll be able to merge that change into your repository. Well done!
Now let’s talk about the difference between merging and rebasing, and when you might want to use one over another.
Merging combines changes from one branch into another by creating a new commit that ties both histories together. It preserves the history of both branches. You should merge when you want to preserve the full history of how work happened. This is commonly used for feature branches that are going to be merged into main, such as when you’re adding new functionality.
On the other hand, rebasing moves or replaces your branch’s commits on top of another branch. It rewrites the history to create a linear and cleaner commit timeline. You should rebase when you want a clean linear history, like when you are updating your feature branch to pull in the latest changes from main. For example, if you are working on a feature, but you want to pull in the latest changes from main before merging.
How do I undo my last commit?
Let’s say that you’re in a situation where you’ve already pushed your commit to your branch, and you want to undo it. You can undo your commit through the GitHub UI.
Open the commit that you want to undo on github.com.
Scroll to the bottom of the commit and select the Revert button.
GitHub creates a new commit that undoes the changes from your previous commit. It’s important to realize that this doesn’t erase the commit history, but rather puts a new change in place that undoes your previous changes. You can now either merge this commit directly or open a pull request with it. Opening a pull request is the safest option when others might be using the branch.
If your changes are local, and you haven’t yet pushed to a branch, you can locally revert your commit by running the following command.
git reset --soft HEAD~1
This removes the commit from your local repository, but keeps your work staged so that you don’t lose any changes. If you would rather undo your changes even locally to reset your workspace, you can use the following command. Just realize that by doing this, you might lose your work!
git reset --hard HEAD~1
How do I update or sync a forked repository on GitHub?
Forking a repository creates your own copy of a project so that you can explore or make changes to it without affecting the original repository. This is especially important when you want to contribute to an open source project. Here’s how you can fork a repository.
Open the repository that you want to fork on github.com.
Select the Fork button at the top of the repository.
Choose the Owner of this forked version, which in most cases will be your GitHub account.
You may optionally rename the repository by providing a new Repository name. By default, forked repositories keep the names of the upstream repository.
At the bottom of the window, select Create fork.
This creates a full copy of the project under your account. To work on it locally, select the Code button and clone it to your machine.
You can learn more about forking by checking our documentation.
Now that you’ve created the fork, you want to make sure that you still pull in the latest changes from the upstream repository. Otherwise, your forked copy can quickly become out of date.
Navigate to the main page for your forked repository on github.com.
At the top of the repository, select the Sync fork button.
Select Update branch in the pop-up menu.
When you do this, GitHub automatically pulls in the latest changes from the upstream repository to keep your fork up to date. You can also do this from the command line.
Open a terminal and navigate to your repository.
Set the upstream repository. Make sure to update the URL in the following command with your original repository URL.
git remote add upstream YOUR_ORIGINAL_REPOSITORY_URL
Pull in the latest changes.
git fetch upstream
Merge the latest changes into your project. Note that the following command assumes that the upstream project uses main as the default branch. If it uses something else, you will need to use that branch in the following command.
git merge upstream/main
This updates your local copy with all of the changes to the upstream branch. So now, you need to push them to GitHub to make sure your repository is synchronized.
git push origin main
Now you know how to work in your own copy of a project and keep your work synchronized!
How do I review a pull request on GitHub?
A pull request (often abbreviated PR) is a place to share code and talk about changes. Here are three helpful practices to keep in mind when you’re reviewing a pull request.
Start by understanding the goal of the pull request. Open the pull request and read the description. See if it has an associated issue, any screenshots, or notes from the author. Knowing the purpose helps you know why the changes exist and what you’re looking for.
Review the code changes in small sections. Open the Files changed tab and move through the changes one group at a time. If something isn’t clear, leave a comment on that line. Ask questions, offer suggestions, or let the author know if you see a better approach. Keep your comments specific so they know exactly what you’re referencing. It might help to open the code on your machine either via the command line or in a codespace to run the code yourself to ensure you understand. Use terms like “nit” if your comment is not a necessary suggestion for merging the pull request.
Highlight what’s going well. When you see code that’s well organized, thoughtful, or teaches you something, mention it! Positive feedback reinforces good patterns and helps teammates feel supported.
Learn more about reviewing pull requests by taking a look at our documentation on the topic.
When everything looks ready, use the Submit review button to approve the changes or request updates.
Copilot code review can also help you understand pull requests and suggest improvements. Note that in order to use Copilot, your organization admin needs to enable Copilot for either your repository or your user account. Once Copilot is enabled, you don’t need to install anything special—Copilot code review will automatically appear as an option in pull requests.
Open a pull request on github.com where you want to use Copilot code review.
Select Reviewers in the top-right.
Select Copilot from the list of suggested reviewers.
In a short amount of time, Copilot will complete its review. You can scroll down and see the comments left by Copilot. It always leaves a “Comment” type of review, not an “Approve” or “Request changes” type of review. This means that Copilot reviews do not count toward required approvals nor will they block merging changes.
Learn more by checking out our Copilot code review documentation.
Next steps
And that’s a wrap! With this episode, we’ve finished another season of GitHub for Beginners, ending with some of the most common questions we’ve seen or heard. We hope that you found this information helpful, and don’t forget to check out our full library of GitHub for Beginners topics.
Happy coding!
The post GitHub for Beginners: Answers to some common questions appeared first on The GitHub Blog.
関連記事
リポジトリ内の全プロジェクトの Git 設定を編集可能に
Vercel は、モノレポで多数のプロジェクトを展開するユーザー向けに、各プロジェクトの Git 設定(コミットステータスやリポジトリディスパッチイベントなど)を一括で管理・適用できる機能を追加した。これにより、個別の設定画面へのアクセスが不要となり、効率的な運用が可能になった。
GitHub for Beginners:VS Code で Git と GitHub を始める方法
GitHub は、Microsoft が提供する無料のコードエディタ VS Code の機能を活用し、Git や GitHub の基本的な操作を学ぶためのチュートリアルシリーズを開始した。これにより開発者はコンテキストスイッチングを減らし効率的に作業できる。
GitHub 2026 年 4 月可用性レポート:10 件のインシデントでサービス性能が低下
GitHub は 2026 年 4 月に 10 件のインシデントが発生し、サービス全体の性能が低下したと報告。同社は透明性向上のため主要事象をブログで公開し、ステータスページの詳細化を進めている。
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み