Git CLI
Branch
# ローカルブランチのみ表示
git branch
# すべてのブランチ
git branch -a
# ブランチ名変更
git branch -m [old_branch] [new_branch]
git branch -m master main
# ブランチ削除
git branch -d <branch_name>
# ブランチ強制削除
git branch -D <branch_name>Clone
git clone [repo_url]Config
# 初期ブランチ名を main に設定
git config --global init.defaultBranch main
# git ユーザー情報を設定
git config --global user.email "Your email"
git config --global user.name "Your Name"
# リモート repo URL を取得
git config --get remote.origin.url
# 改行文字設定を確認
git config --global core.autocrlf
# Git の自動変換を無効化
git config core.autocrlf falseCheckout
# ブランチに切り替え
git checkout <branch_name>
# ブランチを作成して切り替え
git checkout -b <branch_name>Log
git log --oneline
git log --oneline --graph
git log --oneline --graph --allMerge
# [branch-name] を現在のブランチにマージ
git merge <branch_name>
# fast-forward なしでマージ
git merge --no-ff developPull / Push
git pull
git pull origin main
# 初回プッシュ(upstream 設定付き)
git push -u [Remote_Host] [Local_branch_name]:[Remote branch name]Reset
# 指定コミットに戻る
git reset [hash_number]
git reset [hash_number]^
git reset [hash_number]~5
# Soft reset(変更を保持)
git reset --soft HEAD~1
# 単一ファイルを Reset
git reset <filename>Remote
# リモート repos URL を表示
git remote -v
# 新しいリモート URL を設定
git remote set-url origin [new-url]
# リモートを追加
git remote add [name] <url>
git remote add origin <url>Status
git statusStash
# キャッシュされた未コミットファイルを復元
git stash popTag
# タグを作成
git tag v0.1.0
# タグをプッシュ
git push origin v0.1.0
# タグを削除
git tag -d <old-tag-name>
# 注釈付きタグを作成
git tag -a <new-tag-name> -m "Tag message"ファイルの改行文字を確認
git ls-files --eolUse Cases
リモート Git ブランチ名を変更
git branch -a
git push origin --delete <old-name>
git push origin -u <new-name>単一 コマンド:
git push origin :<old-name> <new-name>GitHub SSH を設定
SSH キーを作成 :
ssh-keygen -t ed25519 -C "your_email@example.com"SSH キーを ssh-agent に追加 :
eval "$(ssh-agent -s)"接続 テスト:
ssh -T git@github.comまたは:
exec ssh-agent zshSSH 秘密 キーを ssh-agent に追加 :
ssh-add --apple-use-keychain ~/.ssh/id_ed25519_githubすべての agent を表示 :
ssh-add -lSSH Agent
eval `ssh-agent -s`
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pubGitHub を known hosts に追加 :
ssh-keyscan -H github.com >> ~/.ssh/known_hostsGit Flow
init
git flow initfeature
# feature ブランチを作成
git flow feature start my-feature
git add .
git commit -m "Add new feature"
# develop にマージ
git flow feature finish my-featurebugfix
git flow bugfix start fix-bug
git add .
git commit -m "Fix bug"
# develop にマージ
git flow bugfix finish fix-bugmerge
# Feature または Bugfix を main ブランチにマージ
git checkout main
git merge --no-ff develop
git push origin mainhotfix
git flow hotfix start fix-production-bug
git add .
git commit -m "Fix critical production bug"
git flow hotfix finish fix-production-bug.gitignore
vi .gitignore
# ファイル名
# フォルダ名/
# *.log
:wq # ファイルを保存して終了
git add .
git commit -m "Added .gitignore"Tree
tree -d -I 'target|test'