文書の過去の版を表示しています。


NestDAQ Git Forking Workflow

  • NestDAQ 本体 (nestdaq-user-implではなく) のコードの修正の提案、変更のリクエストがある場合、Forking Workflow というワークフローに従い、pull request (通称: プルリク) を出して NestDAQ のマスターにマージしてもらう。Forking Workflow は AMANEQ-software のコースコードの開発でも採用されており、重要なワークフローなので、ここにメモを残しておく。

Fowking Workflow

  • ここでは、NestDAQ 本体のソースコードを例にとり、pull request まで出してみる。

開発環境を整える: フォークして、手元のPCにクローンして、上流と同期

  1. NestDAQ の Web ページにアクセスする。
  2. Sign in ボタンを押し、自分のアカウントでサインインする。
  3. サインインすると、以下のような状態になる。
  4. 右上あたりの ボタンを押す。
  5. Fork をつくる画面に移行する。基本デフォルトのままでOKのはず。右下の緑の Create Fork ボタンを押す。
  6. nobukoba/nestdaq というリポジトリが作られる。
  7. その後、コマンドライン上での操作になる。
  8. 端末で、Fork した自分のリポジトリをクローンする。
    $ git clone https://github.com/nobukoba/nestdaq.git
    Cloning into 'nestdaq'...
    remote: Enumerating objects: 296, done.
    remote: Counting objects: 100% (54/54), done.
    remote: Compressing objects: 100% (27/27), done.
    remote: Total 296 (delta 38), reused 27 (delta 27), pack-reused 242
    Receiving objects: 100% (296/296), 152.78 KiB | 996.00 KiB/s, done.
    Resolving deltas: 100% (180/180), done.
  9. nestdaq ディレクトリに移動し、git remote -v コマンドで origin を確認。
    $ cd nestdaq/
    $ git remote -v
    origin	https://github.com/nobukoba/nestdaq.git (fetch)
    origin	https://github.com/nobukoba/nestdaq.git (push)
    $ git branch   
    * main
    $ git branch -a
    * main
      remotes/origin/HEAD -> origin/main
      remotes/origin/main
    $ git branch -r
      origin/HEAD -> origin/main
      origin/main
  10. さらに、上流の登録をする。さらに、ブランチも一応確認しておく。
    $ git remote add upstream https://github.com/spadi-alliance/nestdaq.git
    $ git remove -v
    origin	https://github.com/nobukoba/nestdaq.git (fetch)
    origin	https://github.com/nobukoba/nestdaq.git (push)
    upstream	https://github.com/spadi-alliance/nestdaq.git (fetch)
    upstream	https://github.com/spadi-alliance/nestdaq.git (push)
  11. さらに、https://wiki.idempiere.org/ja/Fork_and_Branch_Git_%E3%83%AF%E3%83%BC%E3%82%AF%E3%83%95%E3%83%AD%E3%83%BC を参考に $ git branch –set-upstream-to=origin/main main と打つ。
    $ git branch --set-upstream-to=origin/main main
    Branch 'main' set up to track remote branch 'main' from 'origin'.
  12. idempiere のページにしたがい、upstreamとの同期する。“クローンしたソースコードがマスターリポジトリと同期していることを常に確認する必要があります。”とのこと。
    $ git checkout main
    Already on 'main'
    Your branch is up to date with 'origin/main'.
    $ git pull upstream main
    From https://github.com/spadi-alliance/nestdaq
     * branch            main       -> FETCH_HEAD
     * [new branch]      main       -> upstream/main
    Already up to date.
    $ git pull origin main
    From https://github.com/nobukoba/nestdaq
     * branch            main       -> FETCH_HEAD
    Already up to date.
  13. 準備完了。

ファイルを編集して、commit して自分のリポジトリに push

  1. 環境が整ったので、自分のリポジトリでいつもやっているように、commit & push する。
  2. 例えば nestdaq/CMakeLists.txt のタイポを直してみる。エディタで nestdaq/CMakeLists.txt ファイルの12-14行目を以下のように編集する。 (14行目の add_compiler_options がtypo、正しくは add_compile_options。)
    elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
      message("turn on colored error message of Clang")
      add_compiler_options(-fcolor-diagnostics)
               | | |
               V V V
    elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
      message("turn on colored error message of Clang")
      add_compile_options(-fcolor-diagnostics)
  3. その後、cmake のテストをする。うまくいけば、通常通り commit & push。
    $ git add CMakeLists.txt 
    $ git commit -m "A typo (add_compiler_options --> add_compile_options) was corrected."
    [main 09010b8] A typo (add_compiler_options --> add_compile_options) was corrected.
     1 file changed, 1 insertion(+), 1 deletion(-)
    $ git push
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 335 bytes | 335.00 KiB/s, done.
    Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
    remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
    To https://github.com/nobukoba/nestdaq.git
       4dae50f..09010b8  main -> main
  4. これで push 完了。次はプルリク。

上流にプルリクを出す

  1. 修正を上流にマージしてほしい場合は、pull requests を出す
  2. ブラウザーで自分のリポジトリにアクセスする
  3. 左上あたりの Pull requests ボタン を押す。

Troubleshooting

  • https://wiki.idempiere.org/ja/Fork_and_Branch_Git_%E3%83%AF%E3%83%BC%E3%82%AF%E3%83%95%E3%83%AD%E3%83%BC を見ると、すでにnobukoba/nestdaq.git をクローンしている場合、そのディレクトリに移動して、以下のコマンドを実行すれば、origin の登録ができると書いてある。
    $ cd nestdaq
    $ git remote remove origin
    $ git remote -v # 消えているかチェック。なにも表示されなければOK。
    $ git remote add origin https://github.com/nobukoba/nestdaq.git
    $ git remote -v
    origin	https://github.com/nobukoba/nestdaq.git (fetch)
    origin	https://github.com/nobukoba/nestdaq.git (push)

    ただ、このあと、git remote add upstream https://github.com/spadi-alliance/nestdaq.git としてから git branch –set-upstream-to=origin/main main をすると、以下のメッセージがでる。

    $ git remote add upstream https://github.com/spadi-alliance/nestdaq.git
    $ git remove -v
    origin	https://github.com/nobukoba/nestdaq.git (fetch)
    origin	https://github.com/nobukoba/nestdaq.git (push)
    upstream	https://github.com/spadi-alliance/nestdaq.git (fetch)
    upstream	https://github.com/spadi-alliance/nestdaq.git (push)
    $ git branch --set-upstream-to=origin/main main
    error: the requested upstream branch 'origin/main' does not exist
    hint: 
    hint: If you are planning on basing your work on an upstream
    hint: branch that already exists at the remote, you may need to
    hint: run "git fetch" to retrieve it.
    hint: 
    hint: If you are planning to push out a new local branch that
    hint: will track its remote counterpart, you may want to use
    hint: "git push -u" to set the upstream config as you push.

    この場合、https://qiita.com/kitutune/items/4419f2d726bf8d060ea3https://stackoverflow.com/questions/41412398/how-to-address-git-error-the-requested-upstream-branch-upstream-master-does-n あたりを参考に、git fetch すればよさそう?とりあえず、git fetch して、branch をチェックすると、以下のようになる。

    $ git fetch
    From https://github.com/nobukoba/nestdaq
     * [new branch]      main       -> origin/main
    $ git branch
    * main
    $ git branch -a
    * main
      remotes/origin/main
    $ git branch -r
      origin/main

    なんか git remote remove origin しない場合に git branch -a と git branch -r で見えていた remotes/origin/HEAD → origin/main という行と origin/HEAD → origin/main 行が見えなくなる。なんでだろう。とりあえず、この状態で、git branch –set-upstream-to=origin/main main とすると、うまくいく。

    $ git branch --set-upstream-to=origin/main main
    Branch 'main' set up to track remote branch 'main' from 'origin'.
softwares/nestdaq/git_forking_workflow.1706524254.txt.gz · 最終更新: 2024/01/29 19:30 by kobayash
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0