0
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?

GitHub本当に何もわからない

Posted at

基本的なGitHubコマンドまとめ

セットアップと設定

# 名前とメールアドレスの設定
git config --global user.name "あなたの名前"
git config --global user.email "あなたのメール"

# リポジトリをクローン(ダウンロード)
git clone https://github.com/ユーザー名/リポジトリ名.git

# リモートリポジトリの追加
git remote add origin https://github.com/ユーザー名/リポジトリ名.git

# リモートリポジトリの確認
git remote -v

基本的な作業フロー

# ファイルの変更状態を確認
git status

# 変更をステージング(コミットの準備)
git add ファイル名    # 特定のファイルを追加
git add .           # 全ての変更を追加

# 変更をコミット(記録)
git commit -m "変更内容の説明"

# 変更をGitHubにプッシュ(アップロード)
git push origin ブランチ名

# 最新の変更をGitHubから取得
git pull origin ブランチ名

ブランチ操作

# 現在のブランチを確認
git branch

# 新しいブランチを作成
git branch ブランチ名

# ブランチを切り替え
git checkout ブランチ名

# ブランチを作成して切り替え(上記2コマンドの組み合わせ)
git checkout -b ブランチ名

# ブランチをマージ
git merge ブランチ名

# ブランチを削除
git branch -d ブランチ名

# リモートブランチを削除
git push origin --delete ブランチ名

変更の確認と取り消し

# 変更履歴を確認
git log
git log --oneline    # 簡易表示

# ファイルの変更内容を確認
git diff
git diff ファイル名

# ステージング前の変更を取り消し
git checkout -- ファイル名

# コミット前のステージングを取り消し
git reset HEAD ファイル名

# 直前のコミットを修正
git commit --amend -m "新しいコミットメッセージ"

コラボレーション

# 特定のコミットを取得(他の人の作業内容など)
git fetch origin

# リモートブランチを確認
git branch -r

# マージせずに変更を取り込む(リベース)
git pull --rebase origin ブランチ名

# 競合(コンフリクト)解決後の続行
git rebase --continue

その他の便利なコマンド

# コミット履歴をグラフィカルに表示
git log --graph --oneline --all

# 一時的に作業を退避
git stash

# 退避した作業を復元
git stash pop

# 特定のコミットに一時的に切り替え
git checkout コミットID

このコマンドリストを基本として、必要に応じて使い方を覚えていくと良いでしょう。初めは git statusgit addgit commitgit pushgit pull の基本コマンドを使いこなすことに集中するといいと思います。

0
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
0
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?