Git Github 開発環境
GitとGithubを活用した開発環境構築ガイド:
初心者向けセットアップと基本操作
1. GitとGitHubを活用した開発環境の構築
1-1. はじめに
開発を進める上で、参考となるソースコードや資料を管理するためにGitHubの活用は非常に便利です 。本記事では、Windows 11でのGitのインストールからGitHubの基本的な利用方法までを解説し、より効率的な開発環境の構築をサポートします。
今回使用する環境は以下の通りです:
- OS: Windows 11 Home
- WSL: Ubuntu 22.04.4 LTS (更新済み)
- IDE: VSCode 1.92.2
1-2. PowerShellでGitをインストール
最新版のGitをインストールするために、まずPowerShellを起動し、以下のコマンドを実行します:
PowerShell
winget install --id Git.Git -e --source winget
このコマンドを実行すると、Gitのインストールプロセスが開始されます 。通常、以下のような画面が表示されます (2024年9月現在):
見つかりました Git [Git.Git] バージョン 2.46.0
このアプリケーションは所有者からライセンス供与されます。
Microsoft はサードパーティのパッケージに対して責任を負わず、ライセンスも付与しません。
ダウンロード中 https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/Git-2.46.0-64-bit.exe
██████████████████████████████ 65.0 MB / 65.0 MB
インストーラーハッシュが正常に検証されました
パッケージのインストールを開始しています...
インストーラーは管理者として実行するように要求するため、プロンプトが表示されます。
インストールの途中でWindowsの管理者権限を要求するプロンプトが表示されるので、許可してください 。
インストールが完了すると、「インストールが完了しました」と表示されます 。
インストールが成功したか確認するには、以下のコマンドを実行します:
PowerShell
> git help
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--no-lazy-fetch]
[--no-optional-locks] [--no-advice] [--bare] [--git-dir=<path>]
[--work-tree=<path>] [--namespace=<name>] [--config-env=<name>=<envvar>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
これにより、Gitのヘルプメッセージと、よく使われるコマンドの一覧が表示されます 。
Gitのバージョンを確認したい場合は、以下のコマンドを使用します:
PowerShell
> git --version
git version 2.46.0.windows.1
実行すると、インストールされたGitのバージョン(例: git version 2.46.0.windows.1
)が表示されます 。
1-3. Gitとは?
Gitは、ファイルの変更履歴を記録・管理するための「バージョン管理システム」です 。プログラミングのソースコードだけでなく、ドキュメントや画像など、あらゆる種類のファイルを管理できます 。
1-3-1. Gitを使うメリット
- 過去のバージョンへの復元: 誤ってファイルを変更したり削除してしまったりした場合でも、過去の任意の時点のファイルに戻すことができます 。
- チームでの共同作業がスムーズ: 複数のメンバーで同じプロジェクトに取り組む際に、それぞれの変更を統合したり、競合を解決したりすることが容易になります 。
- 安全なバックアップ: ローカル環境だけでなく、リモートリポジトリにデータを保存することで、万一のデータ消失からファイルを保護できます 。
1-3-2. Gitの主な機能
Gitには、ファイル管理を効率化するための以下の主要な機能があります:
- コミット (Commit): ファイルの変更を記録します 。
- ブランチ (Branch): ファイルの開発ラインを分岐させます 。
- マージ (Merge): 分岐させた開発ラインを統合します 。
- プッシュ (Push): ローカルリポジトリの変更をリモートリポジリに反映します 。
- プル (Pull): リモートリポジトリの変更をローカルリポジリに反映します 。
1-4. GitHubとは?
次に、GitHubに登録してみましょう 。
GitHubは、Gitを用いたバージョン管理サービスです 。世界中の多くの開発者が利用しており、オープンソースプロジェクトの中心地とも言われています 。
以下のサイトにアクセスしてサインアップを完了させてください:
GitHubを利用することで、共同作業がよりスマートになり、そこから世界を動かす何百万ものソフトウェアが生み出されています 。
コメントを残す