Shunsuke KITADA
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Git / GitHub でコードのバージョンを管理する ## 準備 ### Git / GitHub に入門する際の資料 - [サル先生のGit入門〜バージョン管理を使いこなそう〜【プロジェクト管理ツールBacklog】](https://backlog.com/ja/git-tutorial/) - 初心者向け。まずは目を通しておいてほしいです。 - [Git・GitHubの使い方 · 研究室内 IyatomiLab/wiki Wiki](https://github.com/IyatomiLab/wiki/wiki/Git・Githubの使い方) - 研究室OBの [@SyogoShibuya](https://github.com/SyogoShibuya) が書いてくれた wiki です。非常に素晴らしいです。 - [バージョン管理(Git/GitHub) - ソフトウェア1 (2020)](https://eeic-software1.github.io/2020/git/) - 東京大学工学部電子情報工学科・電気電子工学科の進学内定者を対象としたソフトウェア1の講義の講義資料ですが、非常にわかりやすいです。 ### GitHub に ssh 鍵を登録する - [GitHub アカウントへの新しい SSH キーの追加 - GitHub Docs](https://docs.github.com/ja/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account) を参考に ssh 鍵を GitHub に登録しておく --- ## レポジトリを `clone` する - `git clone` コマンドを使って github にある [`IyatomiLab/nlp-onboarding`](https://github.com/IyatomiLab/nlp-team-onboarding) レポジトリを clone する ```shell (system) [australia: ~] $ git clone git@github.com:IyatomiLab/nlp-team-onboarding.git ``` <details> <summary>コマンド実行結果</summary> ```shell Cloning into 'nlp-team-onboarding'... remote: Enumerating objects: 51, done. remote: Counting objects: 100% (51/51), done. remote: Compressing objects: 100% (32/32), done. remote: Total 51 (delta 17), reused 31 (delta 8), pack-reused 0 Receiving objects: 100% (51/51), 55.59 KiB | 262.00 KiB/s, done. Resolving deltas: 100% (17/17), done. ``` </details> - clone したレポジトリに移動する ```shell (system) [australia: ~] $ cd nlp-team-onboarding/ ``` ## 新しい `branch` を `checkout` して作る ### `git branch` コマンドで現在のブランチを確認する - `main` ブランチであることを確認する ```shell (system) [australia: ~/nlp-team-onboarding] $ git branch * main ``` ### `git checkout` コマンドを使って新しいブランチを作る - ここでは `(ユーザー名)/(ブランチの適当な説明)` という名前でブランチを作る - 説明には `XXX のファイルを追加した` や `YYY なファイルを変更した` 等、適切な文言を加える ```shell (system) [australia: ~/nlp-team-onboarding] $ git checkout -b (ユーザー名)/(ブランチの適当な説明) ``` <details> <summary>コマンド実行例</summary> ```shell (system) [australia: ~/nlp-team-onboarding] $ git checkout -b pink/add_files Switched to a new branch 'pink/add_files' ``` </details> ### ブランチが作られたか確認する - 自身が作成たブランチが表示されており、なおかつ `*` マークが頭に付いて選択させていることを確認する ```shell (system) [australia: ~/nlp-team-onboarding] $ git branch main * (ユーザー名)/(ブランチの適当な説明) ``` --- ## git の 4 ステップ `git status`, `git add`, `git commit`, `git push` を覚える レポジトリの clone と branch の checkout はひとまず1回実施すれば大丈夫です。以降、課題解答用のファイル追加・変更の際の以下4ステップの git コマンド実行サイクルが手に馴染むようにしておいてください: - git status - [git add](https://hackmd.io/MkkSlqOERHqUur4znNrAeg#%E8%BF%BD%E5%8A%A0%E3%83%BB%E5%A4%89%E6%9B%B4%E3%81%97%E3%81%9F%E3%81%84%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92-add-%E3%81%99%E3%82%8B) - git commit - git push 以上を順番に説明していきます。 ## 追加・変更したいファイルを `add` する ### 自分用の作業ディレクトリを作成する - `2022` ディレクトリに移動する - `ユーザー名` のディレクトリを作成する ```shell (system) [australia: ~/nlp-team-onboarding] $ cd 2022/ (system) [australia: ~/nlp-team-onboarding/2022] $ mkdir (ユーザー名) ``` <details> <summary>コマンド実行例</summary> ```shell (system) [australia: ~/nlp-team-onboarding] $ cd 2022/ (system) [australia: ~/nlp-team-onboarding] $ mkdir pink (system) [australia: ~/nlp-team-onboarding/2022] $ ls Permissions Size User Group Date Modified Name drwxrwxr-x - pink pink 2022-02-28 18:31  pink # pink ディレクトリが作成されていることを確認する ``` </details> ### 追加しないファイルを予め `ignore` する - [`.gitignore`](https://docs.github.com/ja/get-started/getting-started-with-git/ignoring-files) ファイルを使って追加したくないファイルを予め無視するようにしておきます - データサイズが大きいデータセットや画像ファイル等は追加しないようにします - python のキャッシュファイル `__pycache__` や `.DS_Store` ・ `Thumbs.db` といったディレクトリキャッシュ等も追加しないようにすべきです - **これらのファイルがある github レポジトリを見つけたら要注意です。おそらくそのコードの品質は高くはありません。使わないことをおすすめします** - [`gitignore.io`](https://www.toptal.com/developers/gitignore) から [python 用のテンプレート](https://www.toptal.com/developers/gitignore/api/python) を持ってくると簡単にできます ```shell (system) [australia: ~/nlp-team-onboarding/2022/pink] $ vi .gitignore # # gitignore.io で作成した python 用の gitignore テンプレートを貼り付ける # ``` ### 新規作成・変更したファイルを追加 `add` する - `git add` コマンドを使って変更があったファイルを指定する - 例として言語処理100本ノック第50問目を解答するファイルを `git add` してみる ```shell git add 50.py ``` ### ファイルの追加や変更をレポジトリに記録 `commit` する - `git add` したファイルをレポジトリに記録する - 記録する際にどのような変更か `-m` オプションを付けてメッセージを記述する ```shell git commit -m '言語処理100本ノック第50問目の解答コードを追加' ``` <details> <summary>コマンド実行例と実行結果</summary> ```shell (system) [australia: ~/nlp-team-onboarding/2022/pink] $ git commit -m '言語処理100本ノック第50問目の解答コードを追加' [pink/add_files 0cbdace] 言語処理100本ノック第50問目の解答コードを追加 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 2022/pink_test/50.py ``` </details>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    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

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully