Skip to content

Instantly share code, notes, and snippets.

@0mg
Created September 5, 2010 04:29
Show Gist options
  • Select an option

  • Save 0mg/565751 to your computer and use it in GitHub Desktop.

Select an option

Save 0mg/565751 to your computer and use it in GitHub Desktop.
Git Tips

Git インストールと初期設定

http://help.github.com/win-git-installation/

SSH 公開鍵と秘密鍵を作成

http://help.github.com/msysgit-key-setup/

Git から自分のリモートレポジトリにアクセスするために必要な鍵を作成し、設定する。

ssh-keygen -t rsa -C "[email protected]"

%USERPROFILE% に .ssh というディレクトリが作成され、その中に 2 つの鍵が作成される。

cd /d %USERPROFILE%\.ssh
dir

id_rsa.pub が公開鍵。 id_rsa が秘密鍵。

https://github.com/account/ssh にて id_rsa.pub の内容を キー として追加する。

タイトルは入力不要。

SSH 認証テスト

ssh [email protected]

最終的に、以下のように表示されれば成功。

ERROR: Hi 0mg! You've successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.

名前とメールアドレスを設定

コミットする際に毎回使用する名前とメールアドレスを設定する。

git config --global user.name "0mg"
git config --global user.email "[email protected]"

リモートレポジトリへプッシュ

  1. まず、 Web でリモートレポジトリ hoge.git を作成する。
  2. 次に、空のローカルレポジトリを作成し、
  3. ファイルを追加、
  4. コミット後、
  5. hoge.git の master へプッシュする。

md hoge
cd hoge
git init
touch README
git add README
git commit -m "first commit"
git remote add origin [email protected]:0mg/hoge.git
git push origin master

ローカルブランチ

master 以外へもプッシュできる。まずはローカルブランチを作成しよう。

ローカルブランチ作成

git branch new_branch

ローカルブランチ切替

git checkout other_branch

ローカルブランチ削除

git branch -d bad_branch

ローカルブランチ一覧

git branch

リモートブランチ

  1. ローカルブランチ new_branch ができたら、
  2. ファイルの追加とコミットを済ませ、
  3. 同じ名前のリモートブランチ new_branch を作成し、そこへプッシュしよう。

リモートブランチを作成し、そこへプッシュ

git push [email protected]:0mg/hoge.git new_branch

リモートブランチ削除

git push [email protected]:0mg/hoge.git :bad_branch

ローカルレポジトリ

ファイルの追加および更新

hoge.js を追加・更新する。

git add hoge.js

ディレクトリ内にある全てのサブディレクトリおよびファイルを追加・更新する。

git add .

ファイルの削除

git rm hoge.js

リモートレポジトリをローカルに複製

git clone git://github.com/0mg/hoge.git

コミットログ一覧

git log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment