メモ:git基本コマンド

Gitのコマンドメモです。
例として、ファイル名:hoge.cpp ブランチ名:bra1としてます。

$> git init

  • git 状態確認

$> git status

  • ファイルの追加

$> git add hoge.cpp

  • コミット

$> git commit hoge.cpp

  • コミット(メッセージ付き) 複数行にする場合は -m '1行目' -m '2行目'ってなる。

$> git commit -m 'メッセージ' hoge.cpp

  • ブランチの作成(ここでは)

$> git branch bra1

  • ブランチの一覧を見る

$> git branch

  • ブランチの移動

$> git checkout bra1

  • ブランチの削除

$> git branch -d bra1

とある動作時のメモ (ローカル環境 - ぼっちでの使い方)

  • ケース1(branchからのrebase)

$> git init
$> git add hoge.cpp
$> git commit -m 'first commit' hoge.cpp
$> git branch bra1
$> git checkout bra1
$> vim hoge.cpp // modify
$> git commit -m 'modify' hoge.cpp
$> git checkout master
$> git rebase bra1 // merge
$> git branch -d bra1

  • ケース2(cloneからpush)

$> git config --global push.default matching

グローバル設定に追加

$> git init // path:/home/master
$> git add hoge.cpp
$> git commit -m 'first commit' hoge.cpp
$> git config --add receive.denyCurrentBranch ignore

上記設定をしないと、push先のリポジトリ
currentになっている場合に errorとなる。

$> cd /home/tmp
$> git clone /home/master/
$> vim hoge.cpp // modify
$> git commit -m 'modify' hoge.cpp
$> git push
$> cd /home/master
$> git reset --hard

参考サイト