コマンドラインから始めるGitの基礎
コミット、ブランチ、マージなど、バージョン管理に欠かせないGitコマンドを学びます。
「コマンドラインから始めるGitの基礎」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Command Line Mastery学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Command Line Masteryコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
What is Git?
Welcome to Git basics! Git is a powerful Version Control System (VCS). Think of it as a super-smart history book for your code.
It tracks every change you make, letting you revert to older versions, collaborate with others, and manage different features without stepping on toes. It's essential for modern software development!
Starting a Git Project
To begin tracking a project with Git, you first need to initialize a repository. This creates a special .git folder in your project, where Git stores all its tracking information.
Use the git init command in your project's root directory.
mkdir my_project
cd my_project
git initStaging Your Changes
Before saving your work, Git uses a 'staging area'. This is like a rough draft space where you select which changes you want to include in your next save.
The git add command is used to add files or changes to this staging area.
echo "My first line." > README.md
git add README.mdSaving Your Work (Commit)
Once changes are staged, you 'commit' them. A commit is a snapshot of your project at a specific point in time, with a descriptive message.
Use git commit -m "Your message" to save staged changes to your repository's history.
git commit -m "Initial commit: Added README.md"Viewing Project History
Git keeps a detailed log of all your commits. You can review this history to see who made what changes and when.
The git log command displays your repository's commit history. The --oneline option provides a concise view.
git log --onelineParallel Development with Branches
Branches are a core concept in Git. They allow you to diverge from the main line of development and continue working without affecting the main project.
- Work on new features.
- Fix bugs without breaking stable code.
- Experiment with new ideas.
The main (or master) branch is typically the stable version.
Creating a New Branch
To start a new line of development, you create a new branch. This doesn't move you to the new branch yet; it just creates it.
The git branch <branch-name> command creates a new branch. You can list all branches with just git branch.
git branch feature/login
git branchSwitching Between Branches
After creating a branch, you need to switch to it to start working on that specific line of development. Your files will reflect the state of that branch.
Use git switch <branch-name> to move to an existing branch. It's the modern way to navigate branches.
git switch feature/login
# Now you are on the 'feature/login' branchMerging Branches
Once you've finished work on a feature branch, you'll want to integrate those changes back into your main development line, usually the main branch.
First, switch to the target branch (e.g., main), then use git merge <source-branch> to bring in the changes.
git switch main
git merge feature/loginGit Workflow Check
You've learned the core steps for managing changes with Git. Let's test your understanding of how to save your work.
Git Basics Summary
Great job! You've learned the fundamental Git commands:
git init: To start a new repository.git add: To stage changes for a commit.git commit: To save staged changes to history.git log: To view your project's commit history.git branch: To create and list branches.git switch: To move between branches.git merge: To combine changes from different branches.
These commands form the backbone of managing your code with Git!
よくある質問
「コマンドラインから始めるGitの基礎」レッスンは無料ですか?
はい。「コマンドラインから始めるGitの基礎」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。
「コマンドラインから始めるGitの基礎」で何を学びますか?
コミット、ブランチ、マージなど、バージョン管理に欠かせないGitコマンドを学びます。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Linux Command Line Masteryを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「コマンドラインから始めるGitの基礎」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このLinux Command Line Masteryレッスンでコードを書いて実行できますか?
はい。すべてのLinux Command Line Masteryレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。