git操作方法の覚書


ローカルレポジトリ作成

$ cd /path/to/your/working/directory
$ git init

ファイル変更

$ vi newfile
$ git add newfile
$ git mv srcfile dstfile
$ git rm oldfile
$ git commit -m "comment"
$ git log
$ git log --oneline

リモート(共有)レポジトリのクローンを作成

$ cd /path/to/your/working/directory
$ git clone https://github.com/名前/リポジトリ.git
$ git status

クローンのレポジトリにcommitした変更を元の(originalの)レポジトリへ反映

push権限が必要

$ git push
$ git push origin master

元の(originalの)レポジトリの修正内容をローカルクローンへ反映

$ git fetch
$ git diff FETCH_HEAD
$ git merge FETCH_HEAD
$ git pull
$ git rebase FETCH_HEAD

ローカルクローンを変更する前に別ブランチに変更

$ git branch
$ git branch -a
$ git checkout -b newbranch
(変更)
(コミット)
$ git push -u origin newbranch   (初回のみ)

masterへブランチをマージして削除

$ git merge newbranch
$ git branch -d ブランチ
$ git push origin :newbranch

リモートで削除されたブランチをローカルレポジトリへ反映

$ git remote prune origin
$ git branch -D newbranch
$ git remote show
$ git remote show origin

最終更新日:2015/08/29

↑ トップページ