LoginSignup
0
0

More than 1 year has passed since last update.

現場でよく使うGitコマンドまとめ

Posted at

よく使うGitコマンドを自分用にまとめておく

初期設定

git config --global user.name "[your-name]"
git config --global user.email "[your-email]"
git config --global core.editor 'vim -c "set fenc=utf-8"'
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global core.precomposeunicode true
git config --global core.quotepath false

基本

既存のgitリポジトリのコピーを取得

git clone [repository-url] ./[project-name]

ファイルをステージに上げる

git add [file-name]

ステージに上がっているファイルをコミット

git commit -m "commit message."

ファイル名変更

git mv [old-file-name] [new-file-name]

ファイル削除

git rm [file-name]

コミットログ表示

git log

変更の取り消し

git checkout [file-name]

開発の一連の手順

ローカルbranchを作成して修正した内容をリモートリポジトリにpushする

git clone [repository-url] ./[project-name]
cd [project-name]
git checkout -b [branch-name]
# 何かしら修正
git add .
git commit -m "commit message."
git push origin [branch-name]

branch系

branchを新規作成してそのbranchに移動する

git checkout -b [branch-name]

リモートbranchをローカルbranchにcheckoutする

git checkout -b [branch-name] origin/[branch-name]

branchの一覧を見る

git branch -a

rebase系

mainの内容を開発ブランチに反映させる

git checkout main
git pull
git checkout [branch-name]
git rebase main
# conflictが発生した場合は[conflict-file]を修正して解消する
git add [conflict-file]
git rebase --continue
# conflictが無くなるまで繰り返す
git log
# commit履歴を確認
git push -f origin [branch-name]

衝突を解消した後は git add [conflict-file] の後に git rebase --continue を実行します。
rebaseの場合はconflictを直したらaddしてcommitではなくてrebase --continueします。
rebaseを行ったあとは、branchを普通のpushではなくforce pushする必要があります。
コマンドは上記の通り。

rebaseを諦める

gitのリポジトリはgit rebaseを実行する前に戻ります。

git rebase --abort
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