0
0

More than 1 year has passed since last update.

git コマンドメモ

Posted at

最初に設定しておきたいこと

コミットする前にはユーザー登録の必要あり

git config --global user.name [ユーザー名]
git config --global user.email [メールアドレス]

windows 環境で clone したときに改行コードを勝手に変換させない

git config --global core.autocrlf false

リポジトリ操作

共有可能なリモートリポジトリの作成

git init --bare --shared [パス(url)]

現在のディレクトリにリポジトリ作成

git init

リモートリポジトリの追加

git remote add origin [url]

リモートリポジトリからクローン

git clone [url] .

ディレクトリ指定にピリオドつけると、勝手にフォルダが作成されず、中身のみが展開される

コミット&プッシュするため、まずは追加

git add .

コミット時にはメッセージが必要

git commit -m "なんとかかんとか"

最後にリモートリポジトリにプッシュする

git push origin master

originとはリモートリポジトリのエイリアスのようなもので

git push [url] master

のように、直接指定することもできる。
ブランチに tracking information を追加することで、差分を確認したり push/pull 時に指定を省略できる

git branch --set-upstream-to=origin/master master

なお clone したリポジトリは最初から設定されている模様

サブモジュール関連

プロジェクトにサブモジュールを追加

git submodule add [url] [path]

プロジェクトからサブモジュールを削除

git submodule deinit -f [path]
git rm -f [path]
rm -rf .git/modules/[path]

最後のコマンドは linux 用で windows では delete などになると思われる。
エクスプローラー上から直接消してもいい。

プロジェクト上の全サブモジュールの更新

git submodule foreach git pull origin master

リモートリポジトリの url 変更

現在の url の確認

git remote -v

変更処理

git remote set-url origin [new-url]

origin 以外もいけると思われる。
また、一旦 rm してから add しなおす方法もあり、内部的に違いがあるっぽい。

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