Difference between revisions of "GitHubWorkflow"

From Mu2eWiki
Jump to navigation Jump to search
Line 4: Line 4:
 
The Mu2e computing group manages the Mu2e organization within GitHub.  To have full access to Mu2e software,
 
The Mu2e computing group manages the Mu2e organization within GitHub.  To have full access to Mu2e software,
 
Mu2e collaborators should create a GitHub account, and request to join the Mu2e organization.
 
Mu2e collaborators should create a GitHub account, and request to join the Mu2e organization.
 +
 +
<ol style="list-style-type:roman">
 +
<li>Make sure you have a GitHub account, and that you are added to the Mu2e GitHub organization (https://github.com/orgs/Mu2e/people)</li>
 +
<li>In order to authenticate with github, you will need to set up your ssh keys on the machine you plan to clone / push from, following the instructions [https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account here]</li>
 +
<li>Before we do any developing, we will create our own fork of the official Mu2e Offline repo using the GitHub web interface (instructions [https://guides.github.com/activities/forking/ here]). This fork will be your personal sandbox on GitHub; you can do anything you want to it and it will have no effect on anyone else!</li>
 +
</ol>
  
 
The main Mu2e repository is 'Offline', which contains the algorithms, data structures, art modules and configuration used
 
The main Mu2e repository is 'Offline', which contains the algorithms, data structures, art modules and configuration used
Line 85: Line 91:
 
==Developer Workflow==
 
==Developer Workflow==
  
* To start, you will want to make sure you understand what a [https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes remote] is, and the difference between a branch and a [https://help.github.com/en/articles/fork-a-repo fork]
+
* To start, make sure you understand what a [https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes remote] is, the difference between a branch and a [https://help.github.com/en/articles/fork-a-repo fork], and what a [https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request pull request] is.
 
 
 
<ol style="list-style-type:roman">
 
<ol style="list-style-type:roman">
<li>Make sure you have a GitHub account, and that you are added to the Mu2e GitHub organization (https://github.com/orgs/Mu2e/people)</li>
+
<li>Create our own fork of the official Mu2e Offline repo using the GitHub web interface (instructions [https://guides.github.com/activities/forking/ here]). This fork will be your personal sandbox on GitHub; you can do anything you want to it and it will have no effect on anyone else! Note that you
<li>In order to authenticate with github, you will need to set up your ssh keys on the machine you plan to clone / push from, following the instructions [https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account here]</li>
+
only need to do this once; you can reuse this fork for all your development projects.  We strongly recommend you delete the 'master' branch from your fork: there is no need for this branch in our development model, and it may shadow the master branch in the Mu2e repo, causing ambiguities. </li>
<li>Before we do any developing, we will create our own fork of the official Mu2e Offline repo using the GitHub web interface (instructions [https://guides.github.com/activities/forking/ here]). This fork will be your personal sandbox on GitHub; you can do anything you want to it and it will have no effect on anyone else!</li>
 
 
<li>Create a local clone of your Offline fork. This will be identical to cloning the official mu2e repo (if your fork is up to date), except that the default remote (called "origin") where you will push to by default will point to your fork instead of the official mu2e version.</li>
 
<li>Create a local clone of your Offline fork. This will be identical to cloning the official mu2e repo (if your fork is up to date), except that the default remote (called "origin") where you will push to by default will point to your fork instead of the official mu2e version.</li>
 
   git clone git@github.com:<your user name>/Offline
 
   git clone git@github.com:<your user name>/Offline
<li> To proceed (for example with git remote add commands) you need to change to a git working directory, so cd Offline/</li>
+
<li> Develop inside your git working directory.  Note that you can reuse this directory for multiple development projects if you wish. </li>
<li>(<i>Not required</i>) To be more descriptive about the change you are working on, you can create a new branch to develop your feature on. Again since we will be pushing to your fork, this has no impact on the main Offline, and the only time the branch name will actually show up otherwise is if you are pointing other people to your changes or in the comment of the final merge commit back into the master branch (or if you are working on several things at once and want to keep them separate).</li>
+
   cd Offline/
   git checkout -b <new branch name>
+
<li> Add the main mu2e/Offline repo as a new "remote".  It will be called 'mu2e'.  Note that your fork is also a remote, by default named 'origin'.  You only need to do this once for each development clone.  </li>
<li> Do your work and commit it locally</li>
 
  git commit -m "this is my normal commit onto my local branch"
 
<li> If there are changes in the official master branch, you can grab them and merge them in</li>
 
<ol style="list-style-type:lower-alpha">
 
<li> First you need to add the mu2e/Offline repo as a new "remote"</li>
 
 
   git remote add mu2e https://github.com/mu2e/Offline
 
   git remote add mu2e https://github.com/mu2e/Offline
<li>now you can pull/fetch/merge from that repo (or from any other fork by the same procedure)</li>
+
  git remote -v
   git fetch mu2e
+
<li> Create a branch to develop on. This branch is local to your fork, so has no impact on the main Offline.  The branch name is used for sharing your development work with other people while it is still in progress, and for making your pull request, but has no intrinsic meaning.</li>
  git merge mu2e/master
+
   git checkout -b <development branch name>
</ol>
+
<li> Do your work and commit it locally.  This makes a local 'backup' of your work.</li>
<li>Push your work to your fork</li>
+
  git commit -m "brief comment describing the changes you are committing"
<ol style="list-style-type:lower-alpha">
+
<li> When your development is complete, or when you wish to back it up remotely, or share your work with others, push your branch back to your GitHub fork.  Note this requires you to have setup your GitHub authentication.</li>
<li> If you are working on the master branch of your fork:</li>
+
   git push origin <development branch name>
  git push origin master
+
<li> When your development is complete and tested and ready to be re-integrated with the rest of Mu2e/Offline, go to the GitHub web site and request that your branch be pulled back into Mu2e/Offline.  Your pull request will start the code review process, which may take anywhere from a few hours to a few days. Note that GitHub will not allow you to request a pull if your branch conflicts with other development merged since your clone. </li>
<li> If you are working on a different branch, then the first time you push add the "-u" option to tell git that these branches "track" each other (see [https://lornajane.net/posts/2014/understanding-tracking-branches-in-git tracking branches])</li>
 
   git push -u origin <branch name>
 
</ol>
 
<li> When you are ready to have your changes propagated back into the main mu2e Offline repo, open a pull request.</li>
 
 
<ol style="list-style-type:lower-alpha">
 
<ol style="list-style-type:lower-alpha">
 
<li> In a web browser, open https://github.com/<your user name>/Offline</li>
 
<li> In a web browser, open https://github.com/<your user name>/Offline</li>
<li> If you just pushed, there should automatically be a message about your new changes and a link to automatically open a pull request</li>
+
<li> push the 'new request pull' button associated with your development branch </li>
<li> Otherwise follow the github [https://help.github.com/en/articles/creating-a-pull-request-from-a-fork instructions]</li>
+
<li> More info is available at [https://help.github.com/en/articles/creating-a-pull-request-from-a-fork instructions]</li>
 
</ol>
 
</ol>
<li> On the next software call, be prepared to discuss your changes</li>
+
<li> If your pull request shows conflicts with Mu2e/Offline, you must reconcile those before you can request a pull.  This involves first bringing in the latest Mu2e/Offline master branch, and then merging it with your branch.  Please do NOT perform these steps if there are no conflicts, as the merging process complicates the git history.</li>
<li> If issues are found with your changes, just commit and push again, the pull request will automatically be updated</li>
+
  git checkout master
<li> After a code review, the admins will merge in your branch, and you are done!</li>
+
  git pull mu2e master
<li> Cleanup before continuing:</li>
+
  git checkout <development branch name>
<ol style="list-style-type:lower-alpha">
+
  git merge master
<li> if you created a new branch and you are done with this feature completely, go ahead and delete the branch (remember no history is lost as this whole branch is now part of master, including all provenance)</li>
+
  git push origin <development branch name>
 +
<li> If changes are requested during the code review process, make those on the same development branch as your pull request.  When the changes are complete, commit them, and push your changes back to your fork. GitHub will automatically add the new commits to the pull request, so the reviewers and the the GitHub record will show them. </li>
 +
<li> When the code reviewers are satisfied, one of the software coordinators will merge the pull into Mu2e/Offline.
 +
Once your pull request is merged your changes (commits) will be part of Mu2e/Offline master, and your development branch can be deleted.  If you are uncertain if your branch has been merged or not, select the branch, and push the 'compare' button.  If this comes back stating there is 'nothing to compare to', it means all your changes were already merged.  If it shows differences, those have NOT been merged, so do NOT delete your branch. To delete your branch in GitHub, just push the trash can icon.  You can also delete the branch in your shell, as </li>
 
   git branch -d <my branch name>
 
   git branch -d <my branch name>
 
   git push origin --delete <my branch name> (this deletes the branch from your github fork as well)
 
   git push origin --delete <my branch name> (this deletes the branch from your github fork as well)
<li>if you used the master branch on your fork, or you are planning to continue to develop this feature, just make sure to update it to include the merge commit created by the pull request</li>
+
<li> To reuse your working directory for a new development, first refresh to the current head of master, then create a new branch as described above.  Do NOT reuse branches for new development, as updating those to the head of Mu2e/Offline master will confuse the git history. </li>
   git fetch mu2e
+
   git checkout master
   git merge mu2e/master
+
   git pull mu2e master
</ol>
+
  git checkout -b <new development branch name>
 
</ol>
 
</ol>
  

Revision as of 17:34, 23 January 2020

Introduction

This page describes a recommended git workflow for use with the Mu2e Offline code in GitHub.

The Mu2e computing group manages the Mu2e organization within GitHub. To have full access to Mu2e software, Mu2e collaborators should create a GitHub account, and request to join the Mu2e organization.

  1. Make sure you have a GitHub account, and that you are added to the Mu2e GitHub organization (https://github.com/orgs/Mu2e/people)
  2. In order to authenticate with github, you will need to set up your ssh keys on the machine you plan to clone / push from, following the instructions here
  3. Before we do any developing, we will create our own fork of the official Mu2e Offline repo using the GitHub web interface (instructions here). This fork will be your personal sandbox on GitHub; you can do anything you want to it and it will have no effect on anyone else!

The main Mu2e repository is 'Offline', which contains the algorithms, data structures, art modules and configuration used in simulation production, online filtering, offline reconstruction, and other tasks. The main development branch within Offline is 'master', which should be used for all code development. Offline also contains legacy branches associated with particular data sets, which are maintained for a limited time after the master branch has been developed past those data, as described in the table below.

Mue2/Offline branches
branch name branch purpose support end date
master development end of Mu2e
MDC2018 MDC2018 dataset support end of 2020

To work on a branch other than master:

> git checkout 'BRANCH' 

where 'BRANCH' is the name of the branch

Authentication

If you are following the instructions for accessing Offline as a user, not a developer, you will never need to authenticate yourself to github. If you will do work as a developer than there will be some steps for which you will need to authenticate yourself to github. The page Authentication#Authenticating to github has instructions on two ways to do so

Migrating an existing redmine clone directory to GitHub

You can repoint an existing Offline clone from redmine to GitHub as a way of making an easy transition. To follow these instructions, you must already have a GitHub account that's registered in the Mu2e Organization. The following assumes your redmine clone is in /mu2e/app/Me/MyRedmineClone/Offline, that your GitHub username is MyGitHubName, and that you are working on a branch called MyDevelopmentBranch.

    1. Login to GitHub
    2. Fork Mu2e/Offline in GitHub using the 'Fork' button on the top right of the Mu2e Offline repo page
    3. Add GitHub as a remote to your clone
      > cd /mu2e/app/Me/MyRedmineClone/Offline
      > git remote rename origin Redmine
      > git remote add mu2e https://github.com/Mu2e/Offline
      > git remote add origin https://github.com/MyGitHubName/Offline
      These commands are very fast as no data is actually transferred. You can see your remotes with:
      > git remote -v
      Your clone is now connected to the main Mu2e github repository and your own fork in addition to the Redmine repository. Additionally, we have changed your fork to be the default remote repository (origin)
    4. Push your working branch to your GitHub fork:
      > git push -u origin MyDevelopmentBranch
    After this, you can continue developing in this directory according to the general GitHub workflow described below.

Downloading Offline as a user and NOT a developer

Option 1: you want the default primary version of the code (most people):

  1. clone the repo:
  2. git clone https://github.com/mu2e/Offline
  3. Done!

Option 2: A particular collaborator has a version or branch you want to use:

  1. Find their github user name
  2. Determine what the name of the branch they are working on is (Note: this can be master!)
  3. Clone their fork:
  4. git clone https://github.com/<user name>/Offline cd Offline git checkout origin/<branch name>
  5. Done!

Option 3: You want to use pgit to avoid a long compilation time (EXPERIMENTAL)

  1. Create new directory to put your Offline repo in and move to that directory
  2. mkdir Offline cd Offline
  3. As in Option 2, determine fork and branch name you wish to use
  4. Create a partial checkout clone
  5. pgit2 setup https://github.com/<user name (or mu2e)>/Offline <branch name>
  6. You can now use as normal:
  7. source setup.sh scons -j 4

Developer Workflow

  • To start, make sure you understand what a remote is, the difference between a branch and a fork, and what a pull request is.
  1. Create our own fork of the official Mu2e Offline repo using the GitHub web interface (instructions here). This fork will be your personal sandbox on GitHub; you can do anything you want to it and it will have no effect on anyone else! Note that you only need to do this once; you can reuse this fork for all your development projects. We strongly recommend you delete the 'master' branch from your fork: there is no need for this branch in our development model, and it may shadow the master branch in the Mu2e repo, causing ambiguities.
  2. Create a local clone of your Offline fork. This will be identical to cloning the official mu2e repo (if your fork is up to date), except that the default remote (called "origin") where you will push to by default will point to your fork instead of the official mu2e version.
  3. git clone git@github.com:<your user name>/Offline
  4. Develop inside your git working directory. Note that you can reuse this directory for multiple development projects if you wish.
  5. cd Offline/
  6. Add the main mu2e/Offline repo as a new "remote". It will be called 'mu2e'. Note that your fork is also a remote, by default named 'origin'. You only need to do this once for each development clone.
  7. git remote add mu2e https://github.com/mu2e/Offline git remote -v
  8. Create a branch to develop on. This branch is local to your fork, so has no impact on the main Offline. The branch name is used for sharing your development work with other people while it is still in progress, and for making your pull request, but has no intrinsic meaning.
  9. git checkout -b <development branch name>
  10. Do your work and commit it locally. This makes a local 'backup' of your work.
  11. git commit -m "brief comment describing the changes you are committing"
  12. When your development is complete, or when you wish to back it up remotely, or share your work with others, push your branch back to your GitHub fork. Note this requires you to have setup your GitHub authentication.
  13. git push origin <development branch name>
  14. When your development is complete and tested and ready to be re-integrated with the rest of Mu2e/Offline, go to the GitHub web site and request that your branch be pulled back into Mu2e/Offline. Your pull request will start the code review process, which may take anywhere from a few hours to a few days. Note that GitHub will not allow you to request a pull if your branch conflicts with other development merged since your clone.
    1. In a web browser, open https://github.com/<your user name>/Offline
    2. push the 'new request pull' button associated with your development branch
    3. More info is available at instructions
  15. If your pull request shows conflicts with Mu2e/Offline, you must reconcile those before you can request a pull. This involves first bringing in the latest Mu2e/Offline master branch, and then merging it with your branch. Please do NOT perform these steps if there are no conflicts, as the merging process complicates the git history.
  16. git checkout master git pull mu2e master git checkout <development branch name> git merge master git push origin <development branch name>
  17. If changes are requested during the code review process, make those on the same development branch as your pull request. When the changes are complete, commit them, and push your changes back to your fork. GitHub will automatically add the new commits to the pull request, so the reviewers and the the GitHub record will show them.
  18. When the code reviewers are satisfied, one of the software coordinators will merge the pull into Mu2e/Offline. Once your pull request is merged your changes (commits) will be part of Mu2e/Offline master, and your development branch can be deleted. If you are uncertain if your branch has been merged or not, select the branch, and push the 'compare' button. If this comes back stating there is 'nothing to compare to', it means all your changes were already merged. If it shows differences, those have NOT been merged, so do NOT delete your branch. To delete your branch in GitHub, just push the trash can icon. You can also delete the branch in your shell, as
  19. git branch -d <my branch name> git push origin --delete <my branch name> (this deletes the branch from your github fork as well)
  20. To reuse your working directory for a new development, first refresh to the current head of master, then create a new branch as described above. Do NOT reuse branches for new development, as updating those to the head of Mu2e/Offline master will confuse the git history.
  21. git checkout master git pull mu2e master git checkout -b <new development branch name>

Collaborating on a feature

Sometimes you may want to collaborate on a feature branch with other developers. In this case since the main Offline repository no longer has all the development branches we need to do a couple extra steps

  1. First make sure you actually need to work on the same branch. Are you actually working on the same feature? Can the problem be split into smaller features that can be developed asynchronously? Just because features are related doesn't mean they need to be developed on the same branch
  2. Determine if a large number of people will be developing on the same branch for a significant amount of time. In this case it should become an official branch in the mu2e/Offline like MDC2018
  3. Decide which users fork will be the primary repo for this feature branch, and which branch on that fork you are going to use. If a new branch is needed, the owner of that fork can do as usual:
  4. git clone git@github.com:<their user name>/Offline git checkout -b <new branch name> git push -u origin <new branch name>
  5. There are then a couple options for moving forward: either add all other developers as collaborators on the primary fork, or use pull requests to the primary fork
  6. To add developers as collaborators:
    1. The owner of the primary fork opens https://github.com/<their user name>/Offline
    2. click settings on the right, then collaborators
    3. In the collaborators box, type the github user name of each other developer and hit "Add collaborator"
    4. The other collaborators can then either create a read/write access clone of the primary fork, or add it as a remote to an existing offline repo
    5. git clone git@github.com:<primary user name>/Offline or git remote add primaryfork git@github.com:<primary user name>/Offline
    6. The other collaborators can now push directly to the primary fork as if it was their own:
    7. git push primaryfork <branch name>
  7. To use pull requests:
    1. The owner of the primary fork can just push to it as normal following the normal developer workflow
    2. Other developers clone their own fork, but add the primary fork as a remote
    3. git remote add primaryfork git@githbub.com:<primary user name>/Offline
    4. Other developers can pull in and merge changes from collaborators by fetching/pulling/merging from this remote
    5. git fetch primaryfork git merge primaryfork/<branch name>
    6. Other developers push to their own fork
    7. git push origin <branch namee>
    8. Like in the normal developer workflow, they open a pull request. But then in the compare window before creating the request, change the "base repository" from mu2e/Offline to <primary user name>/Offline (see here)
    9. the owner of the primary fork will need to accept and merge it in
    10. everything else goes like the normal workflow


I have a branch on Redmine that's not on GitHub! How do I use it now?

The official Mu2e GitHub repo will usually have only the master branch (+ maybe some tagged release branches). Currently Redmine has >100 branches. If you have a Redmine branch that is not merged in to master, you will move this branch to your fork to work on it instead.

To start, you should read the development workflow and understand remotes and forks, and have a github account and a fork of the Mu2e Offline repo.

  1. Create a local clone of your Offline fork. This will be identical to cloning the official mu2e repo (if your fork is up to date), except that the default remote (called "origin") where you will push to by default will point to your fork instead of the official mu2e version.
  2. git clone git@github.com:<your user name>/Offline
  3. Add Redmine as a remote to your local clone:
  4. cd Offline git remote add redmine http://cdcvs.fnal.gov/projects/mu2eofflinesoftwaremu2eoffline/Offline.git
  5. Fetch a list of the commits and branches from redmine, and check out whatever branch you need
  6. git fetch redmine git checkout -b <branch name> redmine/<branch name>
  7. Push this branch to your fork
  8. git push origin <branch name>
  9. You should now be able to see your branch on github.com/<your user name>/Offline. You can now continue working on that branch and pushing to your fork, and when it is ready you can submit a pull request to the main Mu2e repo using the developer workflow