LoginSignup
13
12

More than 5 years have passed since last update.

gitの初期設定まとめ

Last updated at Posted at 2014-06-08

gitの勉強会をする機会があったのでその設定等をまとめました。

windows

msysgitの導入

今回は最も手軽に初期設定ができるmsysgitで作業します。
サイトに行ってダウンロードしてきたら、インストーラを起動して基本的にdefaultで大丈夫ですが、

「Select Components」の中で「Additional icons」を選んでおくと便利かと思います。

また、「Adjusting your PATH environment」で「Run Git from the Windows Command Prompt」にするとコマンドプロンプト(comd.exe)やパワーシェル(PowerShell.exe)等でもGitコマンドを使えるようになります。

環境変数についてはお好みで変更してください(丸投げ)

参考URL

WindowsにおけるGit利用環境は整った: Git for Windows と SourceTree for Windows

Mac

Homebrewのインストール

Java JREとXcodeのCommand Toolsもインストール(していなかったら参照)

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
参考URL Mac OS X Mavericks にHomebrewをインストールする方法

gitのインストール

$ brew install git

ubuntu

sourceからインストールする方法

Git依存ライブラリーのインストール

Fedora系

$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

Debianベース

$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev

ライブラリがそろったらスナップショットを持ってきてコンパイルしてインストール

$ tar -zxf git-1.7.2.2.tar.gz
$ cd git-1.7.2.2
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install

これでインストールした後にgitを通してgitの最新版を持ってくることができるようになります。べんり〜

$ git clone git://git.kernel.org/pub/scm/git/git.git

パッケージマネジメントツール(yum, apt-get)でインストールする方法

・yumの場合

$ yum install git-core

・apt-getの場合

$ apt-get install git
参考URL

使い始める-Gitのインストール

ここまででインストールは終了

$ git --version

等で自分の環境にgitがインストール出来ているか確認してください。

名前、メール、色等の初期設定

gitに関する設定は基本的に.gitconfigに直打ちでも対応できます。

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
$ git config --global color.ui true

現在の設定を確認する

$ git config --list

commit log編集用エディタの指定

git config --global core.editor 'emacs'

最近はやりのSublime Textにも設定できます。

参照

Sublime Text2 を Git のコミットエディタにするには
How to use Sublime Text as Git commit message editor?

gitの基本的なコマンド

status

現在の状況を確認

$ git status

add

fileをステージングエリアに追加

$ git add <file>

commit

fileをローカルリポジトリに追加、コミットメッセージの追加

$ git commit 

reset

直前のコミットを打ち消す

$ git reset HEAD

revert

作業ツリーを指定したコミット時点の状態にまで戻す

$ git revert <HashTag>

log

コミットログの表示

$ git log

merge

ローカルブランチのマージ

$ git merge 

rebase

ブランチの派生元の変更

$ git rebase <branch>

stash

現在の作業ツリーの状態を一時的に保管

$ git stash

reflog, cherry-pick

HEADのログを表示、commitの抽出

$ git reflog
$ git cherry-pick <HashTag>

スライド

勉強会に使った資料をSlideShareにアップロードしたので、よければいいねしてシェアしてツイートしてセーブしてやってください笑

Git, Github超入門

13
12
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
13
12