# Git入門 - 演習 ## 事前準備 個人設定を行う ``` $ git config --global user.name "<ユーザ名>" $ git config --global user.email "<メールアドレス>" $ git config --global color.ui auto # メッセージ色を有効化 $ git config --global http.proxy http://proxy.example.com:8080 # proxyがある場合はproxyを設定する $ git config --global https.proxy http://proxy.example.com:8080 ``` ## ex.1 ローカルリポジトリを作成し変更を加える ### リポジトリを作成 ワークスペースを作成する ``` # /path/to/worspace1 は任意のディレクトリ $ mkdir -p ~/path/to/worspace1 $ cd ~/path/to/worspace1 ``` リポジトリを初期化する ``` $ git init ``` 確認コマンドを実行。作成されていることを確認。 ``` $ git status ``` ## ex.2 ファイルを追加し変更を加える。 ファイルを新規作成。 ``` $ echo "hello world" > sample.txt ``` リポジトリの追跡対象に追加 ``` $ git add sample.txt ``` ``` $ git add . # もしくは $ git add sample.txt ``` コミットを実行する ``` $ git commit -m "sample.txtを追加した" $ git status # ワークツリーを確認 $ git log # ログを確認 ``` ファイルを再び編集し、コミットする ``` $ echo "こんにちは" >> sample.txt $ git add . $ git commit -m "文章をを追加した" ``` ## ex.3 機能を作成しリモートに反映 リモートリポジトリをクローンする ``` $ git clone https://git.example.com/path/to/src.git src $ cd src ``` ブランチを作成する。 ※ここでは命名規則やフローをいったん無視する ``` $ git branch sample1 ``` ブランチを確認する。 ※ HEADは作業しているブランチを指している ``` $ git branch # ローカルのブランチを表示 $ git branch -a # ローカル+リモートのブランチを表示 ``` チェックアウトする。 ※ 補足として `git checkout -b sample1` でブランチ作成と切り替えを同時に行う事ができます ``` $ git checkout sample1 ``` プッシュする ``` $ git push origin sample1 ``` ## ex.4 リモートの変更分の取り込みと作業ブランチのマージ masterの変更を取り込む ``` $ git checkout master $ git pull origin master ``` 作業ブランチの内容をmasterに取り込む ``` $ git merge sample1 ``` リモートに反映 ``` $ git push origin master ``` 不要になったブランチを削除する ``` $ git branch -d sample1 ``` ## 参考     <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">GitとGitHub用語について、改正してデジ絵にしました! <a href="https://t.co/pGO2MaqEMs">pic.twitter.com/pGO2MaqEMs</a></p>— ちづみ (@098ra0209) <a href="https://twitter.com/098ra0209/status/1163424568544907265?ref_src=twsrc%5Etfw">August 19, 2019</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up