id:cakephper さんがメモを書かれてますが、知らなかったものとかもあったので社内のredmineにメモってあるものをさらしてみます。
- 初期設定
- git config --global user.name "Hoge Fuga"
- git config --global user.email "hoge@example.com"
- git config --global color.ui auto
- 専用の鍵を使う
$ vi ~/.ssh/config
Host git.example.com
User git
Port 22
Hostname git.example.com
IdentityFile ~/.ssh/id_rsa_git
TCPKeepAlive yes
IdentitiesOnly yes
下書きの途中であげてしまった...(^^;あとで追記する。
- 便利な設定
contrib/completion/git-completion.bashを使うと、プロンプトにブランチ名を表示したり、補完が効いたりします。
詳しくは、id:hirose31さんのこの記事で...
ちなみに私はこんな設定にしてます。
if [ -r "$HOME/.bash_completion.d/git-completion.bash" ]; then # = git-completion.bash
. $HOME/.bash_completion.d/git-completion.bash
PS1="\h: [\$(__git_ps1 \"%s) \")\W] \u\\$ "
else
PS1="${PS1}[\w]\\$ "
fi
この設定はbash用です。zshな人はこちらが参考になるようです。http://blog.s21g.com/articles/1159
- 作業コピーの作成
- git clone git@git.example.com:repos/project.git
- 中央リポジトリから最新情報の取得
- git fetch; git merge origin/master または git pull
- 作業状況を表示
- git status
- 修正をインデックスに登録(コミット対象にする)
- git add -u (既に管理対象になっているファイルで修正されている物をすべて登録)
- git add . (すべてのファイルを登録)
- ローカルでの修正を破棄
- git checkout ファイル
- ローカルの情報を中央リポジトリに送信
- git push origin master
- git push origin ブランチ名
- ブランチの一覧を表示
- git branch (ローカルブランチを表示)
- git branch -a (リモートも含めすべて表示)
- ローカルブランチを作る
- git branch ブランチ名 [ソースブランチ]
- git checkout -b ローカルブランチ名 origin/リモートブランチ名
- ブランチを切り替える
- git checkout ブランチ名
- リモートブランチの削除
- git push origin :branchname
- ローカルブランチを削除する
- git branch -d <ブランチ名>
- git branch -D <ブランチ名> (pushしていないコミットがある場合 -dだとエラーで消せないので-Dで)
- ローカルブランチのリネーム
- git branch -m <現在のブランチ名> <新しいブランチ名>
- 不要なオブジェクトを削除、最適化
- git gc
- リポジトリ内のオブジェクトの圧縮(pack)や不要なオブジェクトの破棄
- 容量の圧縮&性能向上(速度)が見込める。大量のcommitとかmergeをした後すると効果があるらしい。
- git gc
- 作業途中の状態を横にのける
- git stash
- commitしてない変更がある状態で、commitに差があるブランチへは切り替えられないのでstashで横にのけておく
- git stash
- stashしたものを復元
- git stash pop
- stashしたものをクリア
- git stash clean
トピックブランチを使って運用していると、stashをとても良く使います。