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?

Gitを克服したい(自分向け)

Last updated at Posted at 2025-07-04

Gitについて、自分向けの備忘録とまとめです。

個人向けのため、少々おおざっぱな点はご了承ください。
間違えている点などコメントは大歓迎です。

基本サイクル

  1. 自分の作業場(ブランチ)を確認・移動する
  2. 作業する
  3. 変更したいものを選ぶ
  4. 変更しまーす & みんなでチェックする
git branch
git checkout ブランチ名
git add ファイル名
git push origin ブランチ名

あるあるシリーズ

リモートの最新をローカルのブランチに反映したい

段階を踏んで反映したい時

git fetch origin main # リモートの状況をとってくるだけで反映前
git branch
git merge oringn/main # 反映する

一括でもできる

git pul origin main

以下、派生系

git merge --no-ff ブランチ名 -m "マージ" # コミット履歴を綺麗できる
git checkout -b 新規ブランチ名 origin/ブランチ名 # ブランチ作成もする

あるブランチの特定のコミットだけ取り込みたい

取り込み元のコミットのIDを検索し、cherry-pickコマンドを使います。

git checkout ブランチ名      # 取り込み元に移動
git log --oneline           # 一行表示すると見やすい
git checkout ブランチ名      # 取り込み先に移動
git cherry-pick "hash-ID"

stash

使い時

stashコマンドで作業内容を一時退避できます。
作業中を残しつつ、作業前の状態で動作確認したい時にも使えます。
stashはスタックに積まれます。

git stash -m "作業名"
git checkout ブランチ名
git stash apply

git stash push -m "退避名" ファイル1 ファイル2

修正系

ブランチ名を修正する

最初はおおさっぱに命名してしまい、作業を進めていくうちに作業内容と命名のずれが気になってしまった時など。
ブランチ自体を新規作成することになります。

git branch -m 新ブランチ名

直前のコミットを取り消したいけど、変更内容をなくしたいない

タイポなど微妙なミスに気付いた時。

git reset --soft HEAD~1

コマンドを省略する

# コマンドの設定
git config --global alias.br branch
git config --global alias.ch checkout
git config --global alias.st stash

# 確認方法
git config --global --get-regexp alias

lfsコマンド

大容量なファイルを扱う時。コミット履歴とは別に管理できる。

git lfs install
git lfs pull
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?