git の最低限なとこだけ
使ってみようとしたが、意外とはまる。
とりあえずは、無料なgithubやbitbucketに上げておく。
基本をきちんと覚えればどこでもいけるはず。
ssh
キーを利用して暗号化して通信するのでgitの使い方の前にきっちり。
WEB画面を使って、サーバー側にキーを登録後、PCからアクセスする。
改行コードがあるので直接クリップボードへ。
$ xclip -sel clip < ~/.ssh/id_rsa_bitbacket.pub
bitbucket専用のキーを設定しておく。
$ cat .ssh/config Host bitbucket.org User git Port 22 Hostname bitbucket.org IdentityFile ~/.ssh/id_rsa_bitbucket TCPKeepAlive yes IdentitiesOnly yes
まずは、ssh単独で対象サーバに接続できるか試すとよい。
$ ssh bitbucket.org -i ~/.ssh/id_rsa_bitbucket PTY allocation request failed on channel 0 conq: logged in as {username}. You can use git or hg to connect to Bitbucket. Shell access is disabled. Connection to bitbucket.org closed. $ ssh bitbucket.org PTY allocation request failed on channel 0 conq: logged in as {username}. You can use git or hg to connect to Bitbucket. Shell access is disabled. Connection to bitbucket.org closed.
git
すこし、CVS、SVNとは仕組みが違い手順が変わる。
おおまかに以下の流れ。
1. git config
gitクライアントインストール後、すべてのgit処理にたいしてのglobalな設定をしておく。
$ git config --global user.name "{username}" $ git config --global user.email "{useremail}" $ git config --global color.ui auto $ git config --global core.excludesfile ~/.gitignore $ git config --global --list user.name={username} user.email={useremail} color.ui=auto core.excludesfile=/home/osaccount/.gitignore
2. git init
ソースコードのディレクトリをgit処理の対象にする。
.gitディレクトリは削除することで、非対象になる。
$ mkdir /path/to/your/project $ cd /path/to/your/project $ git init $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .classpath # .project # AndroidManifest.xml # bin/ # build.properties # build.xml # local.properties # project.properties # res/ # src/
3. git remote add
リモートなサーバを登録する。
$ git remote add origin ssh://git@bitbucket.org/{username}/{repositoryname}.git $ git remote origin
4. git add
対象ファイルを指定して、インデックスに登録。
$ git add .
5. git commit
ローカル側に保存?される。
$ git commit -a -m 'まずは最初のコミット'
6. git push
リモートなサーバにアップ。
ここではじめてSSHが利用される。
$ git push origin master Counting objects: 28, done. Delta compression using up to 2 threads. Compressing objects: 100% (17/17), done. Writing objects: 100% (28/28), 12.70 KiB, done. Total 28 (delta 1), reused 0 (delta 0) remote: {repositoryname}/acl {username} is allowed. accepted payload. To ssh://git@bitbucket.org/{username}/{repositoryname}.git * [new branch] master -> master
その他
上がって欲しくないファイルは、無視するように。
androidアプリの場合。
/home/osaccount/.gitignore
# built application files *.apk *.ap_ # files for the dex VM *.dex # Java class files *.class # generated files bin/ gen/ # Local configuration file (sdk path, etc) local.properties