GIT WORKFLOWS ============= Greg White, SLAC, 2-Nov-2022. v0 WORKING DRAFT. This draft contains some untested git examples. SUMMARY This document informally lists some git command sequences for common collaborative situations, concentrating on examples of "pull request" when one is NOT using gitHub. That is, how to push and pull to review or test contributions from users cloned repos on a common filesystem, or using only the production repos of SLAC Accelerator software at /afs/slac/g/cd/swe/git/repos/. 0. CLEAN SHOP WORKFLOW Throw away all my staged and unstaged changes, forget everything on your current local branch and make it exactly the same as origin/master. git branch [view branches that exist] git checkout main [make sure you're on main] git fetch origin git reset --hard origin/main 1. USE A BRANCH TO ADD A FEATURE OR MAKE FIXES, POSSIBLY REVIEWED BY "PULL REQUEST" Make changes to a repo on a branch in a local clone, with the intention that the branch will then be merged into main (aka master [1]). Prior to the merge, there may be a pull request for someone else to review. Workflow example includes you or the reviewer merging into origin. So this assumes you really have remembered to make your changes on a named branch before making the changes (which, you know, rareky happens in reality): [Maybe first do "git branch" to view branches that exist, and git checkout main, to make sure you're on main.] git checkout -b fixfacetcatersonlyfacet ... Add and make edits to files git status See what you have changed, files git added, files yet to be git added etc git add [.]|{files} Git add files you've changed or created. Rememebr "git add" means add my change to branch to commit, not only used to add a file] git commit -m "comment" {files} git push -u origin fixfacetcater Now the branch is pushed onto remote ... Do more edits. Say this is the last push for the fix git push Only need push now, not "push origin fixfacetcaters" since -u on first one. ... Make pull request. Email reviewer giving pathname to your repo on AFS for them to clone, and the branch name on which you made your changes for them to pull. Eg: what they would type: git clone /afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev.git git pull origin eg fixfacetcater git diff origin master To make comparison of branchtobereview and master Then either reviewer makes changes, or eamails back with suggestions, or emails ok to push Ready your development branch for pushing. Incorporate suggestions of your reviewer, possibly pulling from their push of branchtobereview. Merge dev branch into master git branch (to verify you're on your devepment branch) git checkout main [or master] git pull Do this preliminary pull step to verify that what you're about to pull into your master, will be onto an up-to-date master If your reviewer has left changes in the origin's deveopment branch you pushed above, then: git pull origin fixfacetcater else if your reviewer has said all is fine you can merge from your own local branch git merge fixfacetcater git push origin master All done! Example ------- dhcp-visitor-222-107:gitWorkflows greg$ git clone greg@rhel6-64.slac.stanford.edu:/afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev.git Cloning into 'swdev'... .. dhcp-visitor-222-107:gitWorkflows greg$ cd swdev dhcp-visitor-222-107:swdev greg$ pwd /Users/greg/Development/sites/gitWorkflows/swdev dhcp-visitor-222-107:swdev greg$ git checkout -b gitWorkflowsDraft Switched to a new branch 'gitWorkflowsDraft' dhcp-visitor-222-107:swdev greg$ git status On branch gitWorkflowsDraft Untracked files: (use "git add ..." to include in what will be committed) gitworkflows.txt nothing added to commit but untracked files present (use "git add" to track) dhcp-visitor-222-107:swdev greg$ git add gitworkflows.txt dhcp-visitor-222-107:swdev greg$ git commit -m "Add gitworkflows first draft" [gitWorkflowsDraft 12db54c] Add gitworkflows first draft 1 file changed, 68 insertions(+) create mode 100644 gitworkflows.txt dhcp-visitor-222-107:swdev greg$ git push -u origin gitWorkflowsDraft greg@rhel6-64.slac.stanford.edu's password: Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 16 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 1.56 KiB | 1.56 MiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 To rhel6-64.slac.stanford.edu:/afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev.git * [new branch] gitWorkflowsDraft -> gitWorkflowsDraft branch 'gitWorkflowsDraft' set up to track 'origin/gitWorkflowsDraft' by rebasing. [Note that gitworkflows.txt was not exported to https://www.slac.stanford.edu/grp/ad/docs/model/swdev/ by the post-recieve hook, because it wasn't pushed to the main branch] Mail a pull request: dhcp-visitor-222-107:swdev greg$ mail -s "pull request on swdev repo" greg@slac.stanford.edu Hi greg, please pull /afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev.git branch gitWorkflowsDraft and let me know what you think or push. Thanks. Then reviewer does: [greg@rhel6-64q tmp]$ git clone /afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev.git Cloning into 'swdev'... done. [greg@rhel6-64q tmp]$ cd swdev/ [greg@rhel6-64q swdev]$ git pull origin gitWorkflowsDraft From /afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev * branch gitWorkflowsDraft -> FETCH_HEAD Updating f792db0..12db54c Fast-forward gitworkflows.txt | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 gitworkflows.txt [greg@rhel6-64q swdev]$ git diff origin master (see differences implied by pullee's branch) Examine teh diffences. test the branch. Either email suggestions, or make changes to the branch and re-push to the branch under review. Eg email back, "looks fine, publish!" git checkout main [or master] git pull (to check what you're going to do to pull into master, is onto an up to date master) If your reviewer has left changes in the origin's deveopment branch you pushed above, then: git pull origin fixfacetcatersonlyfacet else igf your reviewer has said all is fine you can merge from your own local branch git merge fixfacetcatersonlyfacet git push origin master Al 2. SERVICE A PULL REQUEST TO REVIEW CHANGES, WITHOUT GUTHUB This workflow for pull request is for case that repos have no upstream or downsteam in gitHub. It assumes only use of the production git in our AFS. Variation 1. Pullee has pushed wat they want you to review to a special "fixes" branch, secifically for this work, in our git repos area. They named their fixes branch say "cater15334". You review, and possibly make changes to cater15334, and then instruct your pullee to push. if you've made changes to cater15334 , they'll have to repull cater15334 for the changes you made, and merge into master and push to the origin /afs/slac/g/cd/swe/git/repos/. git clone greg@rhel6-64.slac.stanford.edu:/afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/matlab.git cd matlab git pull origin cater15334 1172 git diff origin master 1174 git log [maybe make changes. If you do make changes then git add and commit as usual. if not, simple git push, or email backk the pullee, adn tell them it's ok to push themselves] git add git commit -m "your comments" git push origin cater15334 Variation 2. Pullee has pushed wat they want you to review to a special "fixes" branch in their own cloned repo on their AFS. They have not pushed it to /afs/slac/g/cd/swe/git/repos/ So you've recieved a pull request like: repo : ~jrudolph/work/2020a branch: matlabcater15334 mkdir reviewjakescater cd reviewjakescater git clone greg@rhel6-64.slac.stanford.edu:/afs/slac/g/cd/swe/git/repos/slac/matlab/2020a.git cd 2020a git pull ~jrudolph/work/2020a cater15334 1172 git diff origin master (vew differences) [test. maybe make changes. If you do make changes then git add and commit as usual, to their branch cater15334 in your pulled version.] If you have no changes then email backk the pullee, and tell them it's ok to push themselves. If yuou have made changes: git add git commit -m "your comments" Email pullee saying you've made changes, and to pull and merge from pull ~greg/reviewjakescater/2020a branch cater15334 git fetch --dry-run && git diff @{u} --name-only NOTES AND REFS ============== [1] "main" and "master" are different names for the same designation of a bracnh- they both mean the name of the primary branch, the branch which holds "production". Github used to "master", they now use "main" for cultural sensitivity.