0
0

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.

Gitの基本操作

Posted at

1. リポジトリの初期化

ローカルディレクトリをGitリポジトリとして初期化するには、以下のコマンドを使用します。

git init

2. リモートリポジトリのクローン作成

既存のリモートリポジトリをローカルにクローン(コピー)するには、以下のコマンドを使用します。

git clone <repository_url>

例:

git clone https://github.com/user/repository.git

3. ファイルのステージング

ファイルをステージングエリアに追加するには、以下のコマンドを使用します。

git add <file>

すべての変更をステージングするには、以下のコマンドを使用します。

git add .

4. コミット

ステージングエリアにある変更をリポジトリにコミットするには、以下のコマンドを使用します。

git commit -m "コミットメッセージ"

5. リモートリポジトリへのプッシュ

ローカルリポジトリの変更をリモートリポジトリにプッシュするには、以下のコマンドを使用します。

git push origin <branch>

例:

git push origin main

6. リモートリポジトリからのプル

リモートリポジトリから最新の変更を取得し、ローカルリポジトリを更新するには、以下のコマンドを使用します。

git pull origin <branch>

例:

git pull origin main

7. ブランチの作成

新しいブランチを作成するには、以下のコマンドを使用します。

git branch <branch_name>

例:

git branch feature-branch

8. ブランチの切り替え

別のブランチに切り替えるには、以下のコマンドを使用します。

git checkout <branch_name>

例:

git checkout feature-branch

9. ブランチの作成と切り替えを同時に行う

ブランチを作成し、同時にそのブランチに切り替えるには、以下のコマンドを使用します。

git checkout -b <branch_name>

例:

git checkout -b feature-branch

10. マージ

他のブランチの変更を現在のブランチにマージするには、以下のコマンドを使用します。

git merge <branch_name>

例:

git merge feature-branch

11. ステータスの確認

現在のリポジトリの状態を確認するには、以下のコマンドを使用します。

git status

12. ログの確認

コミット履歴を確認するには、以下のコマンドを使用します。

git log

13. 変更の取り消し

直前の変更を取り消すには、以下のコマンドを使用します。

git reset --hard

ステージングエリアの変更を取り消すには、以下のコマンドを使用します。

git reset HEAD <file>

ワーキングディレクトリの変更を取り消すには、以下のコマンドを使用します。

git checkout -- <file>
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?