最終更新日: 2026-07-24
TOP(About this memo)) > 一覧(Git) > 環境構築・リポジトリ管理
git help commitgit --version--system)--global)--local。ローカルのみオプション省略可能)git config --system [システムへの設定]
git config --global [グローバルへの設定]
git config --local [ローカルへの設定]
/etc/gitconfig~/.gitconfig.git/configに書き込まれる。vim .git/configなどで直接編集も可能。vi .git/configで直接編集するか、以下のコマンドで設定する。git config --local user.name "xxxxxx"
git config --local user.email "xxx@xxx.com"
git config --local remote.origin.url "https://xxxxxx@github.com/xxxxxxx/needs.git"
git config --local -l # ローカルの設定
git config --global -l # グローバルの設定
git config --local --unset user.name
git config --local --unset user.email
core.quotepath:diffなどのファイルパスを出力するコマンドで(-zオプションを付けない場合)、パス中の特殊文字をバックスラッシュ付きのダブルクォートで囲む機能。OFFにしても問題なさそう。# パーミッションの変更を無視する
git config --local core.filemode false
# ファイル名の大文字・小文字の変更を検知する
git config --local core.ignorecase false
# カラー設定
git config --local color.ui true
git config --local color.diff auto
git config --local color.status auto
git config --local color.branch auto
# 日本語ファイル名をエスケープせずに表示
git config --local core.quotepath false
# 濁点つきのファイル・ディレクトリが分けて表示されてしまうUTF8-MAC問題の対策
git config --local core.precomposeunicode true
git cloneで手元にやってくる。git clone <リモート> <ローカルのフォルダ>
git clone -b <ブランチ名> <リポジトリのアドレス>
git push <name> <branch>で、ローカルのコードを<name>という名称のリモートリポジトリの<branch>ブランチにアップロードする。<name>は「サーバーを表すただの短縮名」なので、URLでも良い。
git push origin mastergit push git@github.com:DQNEO/sample.git master:masterのようになる。master:masterは、ローカルのmasterをリモートのmasterに反映させるという意味。git config --listで確認できる。
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=https://github.com/ユーザー名/レポジトリ名.git
-vで詳細を表示)git remote
git remote add <name> <url>
<name>はリポジトリの場所(URL)の別名。git remote add origin git@github.com:BabaShun/sample.git
git remote rm origin。<name>という短縮名でリモートリポジトリを登録する」という命令なので、短縮名を使わずURLを直接コマンドに渡す(例:git push <URL> <ブランチ>)ことも可能ではある。便利なので通常は短縮名を使う。git remote set-url origin <新しいURL>
git remote -v # 確認
git init
git add .
git commit -m "Initial commit"
git config --local user.name "xxx"
git config --local user.email "xxx@xxx.com"
git remote add origin https://github.com/XXXX/XXXXXX.git
git push -u origin master
git archiveでエクスポートする(エクスポート参照)。cd /path/to
mkdir myapp.git # リモートリポジトリのディレクトリは.gitをつけるのが慣例
cd myapp.git
git --bare init --shared
--bare:作業ファイルを持たない、pushされるための専用リポジトリ(最小限のリポジトリ。ベアリポジトリという)。--shared:リポジトリを共有可能にするためのオプション。これがないとpushしてもファイルを作成できない。lsでファイルが作成されていることを確認できる(例:branches config description HEAD hooks info objects refs)。cd /tmp/
git clone localhost:/path/to/myapp.git
git push --mirror
refs/がそのままリモートリポジトリのrefs/にプッシュされる。git clone --mirror <URL>
git init --bare
git remote add --mirror=fetch origin <URL>
git fetch origin
git clone(SSH経由)を実行するとrootで実行されることになるため、秘密鍵が想定しているユーザーのホームディレクトリ以外(例:/home/ec2-user/ではない場所)から参照されてしまうことがある(?)。~/.ssh/configに以下のように設定する。Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/sample/id_rsa
git@github.com:sampleProject/aaaa.gitのgithub.com部分をgithubに変える必要がある。GIT_SSH_COMMAND="ssh -o BatchMode=yes"を設定してバッチモードにすればよい。
GIT_SSH_COMMAND='ssh -F /home/ec2-user/.ssh/config -i /home/ec2-user/.ssh/id_rsa -o BatchMode=yes' git clone ...
git cloneするだけでよい。git remote add <適当なname> <fork元のURL>/xxx.git
git fetch <適当なname>
git checkout master
git merge <適当なname>/master
git remote add <好きな名前> <コピー元のURL>としてからgit push -f <好きな名前> <ブランチ名>する
--bareをつけてcloneすると、gitファイルだけを取得できるので、そこからgit push --mirror <コピー先リポジトリ>で全てをpushする
git remote addのやり方と同様にできる可能性がある。.gitattributesファイルを作成し、以下を記述する(例)。.gitignore export-ignore
.gitattributes export-ignore
.gitignoreに書いてあるファイルは記載不要(.DS_Storeやideaディレクトリなど、.gitignore側に記載済みであれば不要)。git add、git commitしておく。mkdir /path/to/tmp
git archive master | tar -x -C /path/to/tmp
-x:解凍、-C:解凍先hogeというリポジトリの中で、fugaというリポジトリを外部からgit cloneしてきた場合、hoge側でgit pushしてもfugaの中身はpushされない。git submodule add <外部リポジトリ> <ローカルで格納したいディレクトリ>