Git_Workflow_and_Notes - UW-Libraries/druw GitHub Wiki

Git Development Workflow

The master of this document lives at:

https://github.com/UW-Libraries/druw/wiki/Git_Workflow_and_Notes

Configure your identity

Vagrant will set up a generic identity for your commits, so you'll want to change the defaults. You can run these commands in any directory as they make a global change.

  1. Set your user name: git config --global user.name "Jane Doe"
  2. Set your e-mail: git config --global user.email [email protected]

Clone main repo and create a branch*

  1. Clone repo:

  2. Checkout a new branch with a name indicative of what you will be working on:

    • git checkout -b <branchname>

    Note: One will often name a branch partly after its issue # on github/bitbucket. like: git checkout -b 23_fix_widgets so when I work on my commit message, i can do: "Add widget frobulation strategy to fix widget behavior. Fixes #23" which on github (and maybe on bitbucket?) will autoclose the referenced issue #.

Make changes on the new branch…

Do what you came to do…

Add, commit, push changes:

  1. git add FILE1 FILE2 FILE3
  2. git commit or git commit -m "Descriptive commit message"
  3. git push origin <branchname>

Rebase from upstream master (UW-Libraries/druw) & Create pull request

This needs to be updated for our post-fork world

When ready to add commits to main repo, make sure your forked branch is in sync with the main master before creating a pull request on UW-Libraries/druw

  1. git checkout master

  2. If you haven't previously, add UW-Libraries/druw as an additional remote repo for pulls:

    You only have to do this the first time you rebase a given clone.

  3. git pull upstream master

  4. git checkout <branchname>

  5. git rebase master

  6. git push origin <branchname>

  7. Copy that pull request url into a browser and continue or just go to the bitbucket gui to create the pull request. Have someone else review and merge your pull request.


Miscellaneous Git Notes

Forks

  1. Create a bitbucket account if you don't have one.
  2. Fork the druw repo according to bitbucket instructions for forking
  3. Get your dev environment going. Docker containers and druw application
  4. Edit metadata spreadsheet to indicate you've started working on a term.
  5. Vaguely follow the above instructions to add a new term.
  6. Once rspec tests pass, create a pull request

Branches (limited to devs for now)

If you have been working on the master branch and have not committed any of your changes, you can still turn your existing work into a branch.

  1. git branch somename master or git checkout -b my_branch
  2. make changes and add and commit them
    git commit -a -m "Adding accrual_policy to metadata options"
  3. make sure master is up to date
    git checkout master
    git pull
  4. return to branch and push
    git checkout branch
    git push origin [ branch ]
  5. Copy that pull request url into a browser and continue or just go to the bitbucket gui to create the pull request. Check 'delete branch after merge' or somesuch.
  6. After PR is merged, update local master and tag for production
    git checkout master
    git pull #to update master
    git tag production-[date]
    git push origin --tags or
    git push origin [tagname]

Squashes

  • git checkout [ branch ]
  • git rebase -i HEAD~# (where # is the number of commits to squish) == git rebase -i HEAD^^^^
  • (This is where you'll drop into vi and change line 1 from "pick" to "reword", and change lines 2-3 from "pick" to "fixup)
  • (That should work A-OK, and you shouldn't have merge conflicts)
  • git push origin [branch] -f (note: don't ever use the -f when pushing to a shared repo)

Detritus

pretty git history
git log --pretty=format:"%C(yellow)%h\ %Cgreen%ad\%Cblue\ %an%Cred%d\ %Creset%s" --graph --decorate --date=short

git pull vs. git fetch

  • git pull is an alias for fetch and merge
  • git fetch just fetches

References

⚠️ **GitHub.com Fallback** ⚠️