git | ぽにょ、ぽにょぽーにょ

ぽにょ、ぽにょぽーにょ

2012年からWebエンジニア。
プログラムとか、趣味とか、人生とかの備忘録。

なんかアメブロってださくて使いづらいからそのうち引っ越しまふ。

h1. Githubの使い方

https://help.github.com/articles/create-a-repo


h2.自分のリポジトリにあげる方法

1.自分のリポジトリを作る

2.リポジトリにあげるディレクトリを作る
 mkdir test

3.そのファイルの中で git initを実行する

4.リポジトリにあげたいファイルをgit addする

あげたくないものは.gitがあるところで
.gitignoreをつくって下記みたいにいれる。

<pre>
.svn
.swp

images
application/.*
application/logs
application/cache
application/errors
application/hooks
application/language
application/logs
application/config
application/core
application/index.html

</pre>


addとかignoreしたものは
git statusで見れる
addを取り消す場合は git rm --cached ******
(ディレクトリの場合は-rをつける)

リモート上のファイルを消す場合は
git rm ファイル名


5.コミットする
 git commit -m 'comment'

6.pushする。 

<pre>
  git remote add origin https://github.com/username/Hello-World.git
</pre>

7.gitのマスターブランチにpushする。
git push origin master
※git rm したときはローカルからも消えます。



エラーが出た時
# git push origin master
To https://github.com/hooor/wiki.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxxxx/xxxxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

[解決方法]

# git pull https://github.com/xxxxxxxxxxxx/xxxxxxx.git master
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

# git push origin master

Counting objects: 29, done.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (28/28), 81.60 KiB | 0 bytes/s, done.
Total 28 (delta 3), reused 0 (delta 0)
To https://github.com/xxxxxx/xxxxxi.git
   c259bf8..a51f594  master -> master