2
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 5 years have passed since last update.

よく使う!Gitコマンドまとめてみた

Posted at

Railsチュートリアルを進めていて定期的にGitのコマンドを使うのと、最近業務でもGitを使う機会があったのでよく使用するコマンドをまとめてみました。
##add
ワーキングスペースからファイルなどをステージへ移動する

// ファイルをまとめて指定する
 git add .

// 識別子がhtmlのファイルをまとめて指定する
git add *.html

// ファイルを指定する
git add [ファイルパス]

##commit
ステージに追加された変更をリポジトリに保存する

// ファイルをまとめて指定する
 git commit .

// ファイルを指定する
git commit [ファイルパス]

// 直前のコミットを取り消す
git commit -a

// コミットメッセージを入力する
git commit -m "[コミットメッセージ]"

##push
ローカルリポジトリからリモートリポジトリへ変更を反映させる

// プッシュする
git push [リモートリポジトリ名] [ブランチ名]

// originリポジトリのmasterブランチへプッシュする
git push origin master

##clone
既存のGitリポジトリのコピーを取得する。リモートリポジトリをローカルリポジトリとして保存する

// クローンする
git clone [URL]

##init
リポジトリを新規に作成する。

// 初期化する
git init

##branch
ブランチを作成する

// ブランチを作成する
git branch [ブランチ名]

// ブランチの一覧を表示する
git branch

// ブランチ名を検索する
git branch --list '検索ワード'

// ブランチ名を変更する
git branch -m [変更前ブランチ名][変更後ブランチ名]

// ローカルブランチを削除する
git branch -d [ブランチ名]

##merge
マスターブランチに各ブランチで編集した作業を反映させる

// マージする
git merge [ブランチ名]

// コンフリクトが生じコミットが行われていない状態でマージを中断する
git merge --abort

// コンフリクトを解決しマージを再開する
git merge --continue

##checkout
作業ブランチを切り替える。指定したコミットの状態を現在の作業ツリーに展開する

// masterにブランチを切り替える
git checkout master

// 新規ブランチの作成と切り替えを行う
git checkout -b [ブランチ名]

##status
ファイルの更新状態などを確認する

// 全体の変更を確認する
git status

// 特定のファイル・ディレクトリの変更を確認する
git status [ディレクトリパスorファイルパス]

##fetch
リモートリポジトリから最新情報をローカルリポジトリに持ってくる

// フェッチする
git fetch [リモートリポジトリ名] [ブランチ名]

// originリポジトリのmasterブランチへフェッチする
git fetch origin master

##pull
git fetch と git merge を連続で実行する

// プルする
git pull [リモートリポジトリ名] [ブランチ名]

// originリポジトリのmasterブランチへプルする
git pull origin master

##reset
コミットした内容を取り消す

// 指定したファイルをステージングから削除
git reset [ファイル名]

diff

2つのファイルを比較して違いなどを探す。マージ前などに行う。

// リポジトリの中にあるファイル全てを比較する
git diff

// 特定のファイルを比較する
git diff [ファイル名]

##stash
別のブランチに切り替えて作業をする際に変更を一時的に退避することができる

// 変更ファイルを退避する
git stash

// 現在のどの変更を退避しているかを確認する
git stash list

##終わりに
各コマンドの基本的な使い方をまとめることができました。Gitにもう少し慣れてきたら各コマンドごとにオプションをまとめてみたいです。

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