LoginSignup
0
2

More than 1 year has passed since last update.

【Git】本当によく使う基本コマンド

Last updated at Posted at 2021-12-10

 はじめに

Gitのよく使う基本的なコマンドについて自分の備忘録兼ねて整理しました。
開発を行う上でも必須のコマンドばかりです。

ローカルリポジトリの新規作成

.gitディレクトリを新規作成します。

git init

リモートリポジトリをクローンする。

git clone リポジトリ名

リモートリポジトリを登録する。

※originはリモート名。originという名前でリモートリポジトリを登録する。

git remote add origin URL

変更をステージする

//sample.htmlをステージする。
git add sample.html
//ワークツリーの変更分をすべてステージする。
git add .

変更を記録する(コミットする。)

ステージにあるファイルを記録します。

git commit
//コメント付きで記録する。
git commit -m "メッセージ"
//差分を確認する。
git commit -v 

現在の変更状況を確認する。

git status

変更差分を確認する。

※「git diff ファイル名」で特定のファイル名のみの指定も可能。

//ステージとワークツリーの比較
git diff
//ステージとリポジトリの比較
git diff --staged

変更履歴を確認する。

git log
//1行で表示する。
git log --oneline
//ファイルの変更差分を表示する。
git log -p index.html
//表示するコミット数を指定する。
git log -n 数字

push(リモートリポジトリに送信)する。

originはリモート名
masterは送信するブランチ名

git push origin mater

 コマンドにエイリアスを付ける

以下は「commit」に「co」というエイリアスを付けている。
以降、コミット時に「git co -m "エイリアスを付けました。"」のように省略して書くことができる。
また、「git config --list」で設定内容を確認することができる。

git config --global alias.co commit
0
2
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
2