Gitコマンド

git
本項は書きかけの記事です。正確な情報は公式サイト、公式ドキュメント、記載の参照サイトでご確認ください。

目次

+ 読む

概要

2005年12月、Linuxの父Linus Benedict Torvalds、 濱野純氏らによって開発された分散管理型バージョン管理ツール。

初期設定

- 開く
# 新規フォルダからリポジトリを作る(ローカル)
mkdir myrepo && cd myrepo
git init
echo "# myrepo" > README.md
git add .
git commit -m "chore: first commit"
 
# GitHub等に空のリポジトリを作って push
git remote add origin https://github.com/USER/REPO.git
git push -u origin main
 
# USBディスク内に“裸”リポジトリ(バックアップ/配布用)
# 共有用の bare リポジトリを作る
git init --bare E:/backup/repos/myrepo.git
 
# 元の作業リポジトリから接続
cd E:/work/myrepo
git remote add origin E:/backup/repos/myrepo.git
git push -u origin main
 
 
# SSH鍵(ポータブル運用)
# HOME をUSB側に向けてある前提(0)参照)
ssh-keygen -t ed25519 -C "you@example.com"
# 公開鍵を表示してGitHub/GitLabに登録
type ~/.ssh/id_ed25519.pub      # PowerShell: Get-Content ~/.ssh/id_ed25519.pub
# check
ssh -T git@github.com
 
# Permission denied (publickey)公開鍵をGitホスティングに登録/
ssh -T git@github.com
 
# 別のGitが優先される  順序確認。PortableGitの ...\PortableGit\cmd\git.exe が先頭になるようPATH調整。
where git
 
# 改行コード、パス長の設定を確認
git config --list --show-origin | Select-String -Pattern 'core\.autocrlf|core\.eol|core\.safecrlf|core\.longpaths'
git config --get core.autocrlf
git config --global --get core.autocrlf
git config --system --get core.autocrlf
git config --local  --get core.autocrlf   # リポジトリ内で実行時
 
# 改行コード設定(Windows編集→Git管理時の定番)
git config core.autocrlf true
 
# パス長設定git config --global core.longpaths true
 
# 共有フォルダ設定:“このディレクトリは安全でない”警告(共有フォルダ等)
git config --global --add safe.directory 'E:/work/myrepo'
 
# 確認: .gitattributes での制御が最優先です(* text=auto など)
git config --show-scope --get core.autocrlf
git config --show-scope --get core.longpaths
 
 

タグ:

git
最終更新:2025年10月13日 22:50