{"id":18839087,"url":"https://github.com/solareenlo/git-practice","last_synced_at":"2026-01-26T01:33:18.082Z","repository":{"id":93865745,"uuid":"171647660","full_name":"solareenlo/git-practice","owner":"solareenlo","description":"gitの基本的な使い方","archived":false,"fork":false,"pushed_at":"2019-02-21T02:16:21.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-29T20:13:53.658Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solareenlo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-20T10:00:01.000Z","updated_at":"2019-02-21T02:16:23.000Z","dependencies_parsed_at":"2023-03-08T12:45:38.040Z","dependency_job_id":null,"html_url":"https://github.com/solareenlo/git-practice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/solareenlo/git-practice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solareenlo%2Fgit-practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solareenlo%2Fgit-practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solareenlo%2Fgit-practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solareenlo%2Fgit-practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solareenlo","download_url":"https://codeload.github.com/solareenlo/git-practice/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solareenlo%2Fgit-practice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28763950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"ssl_error","status_checked_at":"2026-01-26T00:37:25.959Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T02:41:50.967Z","updated_at":"2026-01-26T01:33:18.067Z","avatar_url":"https://github.com/solareenlo.png","language":null,"readme":"# git-practice\n\n## gitの構成\n- 作業ディレクトリ\n- ステージングエリア（インデックス）\n- リポジトリ（ローカル, リモート）\n\n## gitの設定\n```bash\n# gitへユーザー名を登録\ngit config --global user.name \"solareenlo\"\n\n# gitへメールアドレスを登録\ngit config --global user.email \"solareenlo@test.com\"\n\n# gitを色づける\ngit config --global color.ui true\n\n# commitしたときのエディタをvimに設定する\ngit config --global core.editor vim\n\n# gitの設定一覧を見る\ngit config -l\n\n# gitのhelpを見る\ngit config --help\n```\n\n## 初めてのcommit\n```bash\n# gitの初期化\ngit init\n\n# 作業ディレクトリからステージングエリアへ\ngit add index.html\n\n# ステージングエリアからリポジトリへ\ngit commit\n# タイトルとか変更内容を書いて, :wq\n\n# 変更のlogを見る\ngit log\n```\n\n## gitのlogを見る\n```bash\n# logをコンパクトに見る\ngit log --oneline\n\n# logと共に変更内容も見る\ngit log -p\n\n# どのファイルが変更なったかを見る\ngit log --stat\n```\n\n## 現在の状態を把握する\n```bash\n# 現在の状態を見る\ngit status\n\n# ファイルの変更を無かったことにする\ngit checkout -- index.html\n```\n\n## 差分を確認する\n```bash\n# ファイルの差分を見る\ngit diff\n\n# ステージングされたファイルの差分を見る\ngit diff --cached\n```\n\n## gitでのファイル操作\n```bash\n# 現在のディレクトリ以下全部のファイルをaddする\ngit add .\n\n# gitでのファイル削除\ngit rm index.html\n\n# gitでのファイル移動\ngit mv index.html\n```\n\n## gitの管理に含めない方法\n```bash\n# .gitignoreファイルを作り, その中にgitに含めないファイルを記述する\nvim .gitignore\n*.log\n\n# .gitignoreがある場所から遡ってはignoreされない.\n# ので, サブディレクトリだけ.gitignoreしたい場合は, サブディレクトリ内に.gitignoreを入れておく.\n```\n\n## 直前のcommitを変更する\n```bash\n# 1つcommitする\ngit commit -m 'コミットを1つ追加'\n\n# 直前のcommitを上書きする\nvim index.html\ngit add .\ngit commit --amend\n```\n\n## 過去のバージョンに戻る（１）\n```bash\n# 作業ディレクトリもステージングエリアも直前のcommitへ戻す\ngit reset --hard HEAD\n\n# 2つ前のcommitに戻る\ngit reset --hard HEAD^\n\n# 指定したidにcommitを戻す\ngit reset --hard hash値(最低7桁)\n```\n\n## 過去のバージョンに戻る（２）\n```bash\n# commit変更したけど, やっぱり変更前のcommitに戻りたいときは\ngit reset --hard ORIG_HEAD\n# ORIG_HEADには前回取り消されたHEADの情報が1つだけ入っている.\n```\n\n## branchを使う\n```bash\n# 現在のbranchを確認する\ngit branch\n\n# 新しいbranch hogeを作成する\ngit branch hoge\n\n# hoge branchに移動する\ngit checkout hoge\ngit branch\n\n# master branchに戻る\ngit checkout master\ngit branch\n```\n\n## branchをmergeする\n```bash\n# master branchにhoge branchをmergeさせたい\ngit checkout master\ngit merge hoge\n\n# いらなくなったhoge branchを削除する\ngit branch -d hoge\n\n# masterにmerge済みのbranchを確認する\ngit checkout master\ngit branch --merged\n\n# masterにまだmergeしていないbranchを確認する\ngit checkout master\ngit branch --no-merged\n\n# 作業途中でmergeしたときに, まだcommitしたくないときは, stashを使って一時的に変更内容を退避させる.\ngit stash save 'コメント'\n\n# stashで退避させた情報の一覧表示\ngit stash list\n\n# 退避させるたびに, この一覧の上に退避データが積み上がっていく.\n# 対比した内容を取り出すには\ngit stash pop\n# 引数をつけない場合, listで表示された一番上の内容が取り出される.\n```\n\n## mergeの衝突を解消する\n```bash\n# branch切って, すぐにhogeに移動する\ngit checkout -b hoge\nvim index.html\ngit add .\ngit commit -m 'hogeで変更したよ'\ngit branch master\nvim index.html\ngit add .\ngit commit -m 'masterでも変更したよ'\ngit merge hoge\n\u003e CONFLICT (content): merge conflict in index.html\nvim index.html\n# index.htmlのいらないところを削除するだけ\n# hogeかmasterのどちらかの変更を残すということ.\ngit add .\ngit comit -m 'conflictを解消したよ'\n```\n\n## tagを付ける\n```bash\n# 直前のcommitにidに代わるわかりやすいv1.0というtagを付ける\ngit tag v1.0\n\n# tagを確認する\ngit tag\n\n# tagを使ってcommit内容を確認する\ngit show v1.0\n\n# 特定のcommitにtagを付ける\ngit tag v0.9 id(hash値)\n\n# tagの削除\ngit -d v0.9\n```\n\n## エイリアスを付ける\n```bash\ngit config --global alias.co checkout\ngit config --global alias.st status\ngit config --global alias.br branch\ngit config --global alias.ci commit\ngit config -l\n```\n\n## 初めての共同作業\n```bash\n# 共有リポジトリを作成\n# 共有リポジトリには.gitを付けるのが通例\nmkdir ourweb.git\ncd ourweb.git\ngit init --bare\n# これで管理ファイルだけが管理され, commitとかはしない設定になる.\n\n# 別のリポジトリを現在のリポジトリにoriginとして登録する\ngit remote add origin ~/path/to/ourweb.git\ngit config -l\n\u003e remote.origin.url=/home/path/to/ourweb.git\n\n# 登録した別のリポジトリ(origin)を削除する\ngit remote rm origin\n\n# 現在のリポジトリ(master)の内容をremoteしたディレクトリ(origin)にpushする\ngit push origin master\n# originにmasterをpushする.という意味.\n\n# ourweb.gitをmyweb2としてcloneして作業する\ngit clone ~/path/to/ourweb.git myweb2\ncd myweb2\ngit log\nvim index.html\ngit add .\ngit commit -m 'line2 added'\ngit push origin master\n# 変更内容(master)をoriginにpushした\n\n# 別のユーザーが上記の変更をpullする\ngit pull origin master\ngit log\n```\n\n## 共同作業でコンフリクトが起こったら\n```bash\n# Aさんが先に変更を加えた\nvim index.html\ngit commit -am 'line 3 added'\ngit push origin master\n\n# Bさんも後から同様の場所に変更を加えた\nvim index.html\ngit commit -am 'line third added'\ngit push origin master\n\u003e CONFLICT (content): Merge conflict in index.html\n# pushする前にpullしてまずはconflictを解消する\ngit pull origin master\nvim index.html\ngit commit -am 'conflict fixed'\ngit push origin master\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolareenlo%2Fgit-practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolareenlo%2Fgit-practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolareenlo%2Fgit-practice/lists"}