class: center, middle, inverse, title-slide # Workflow ## GitHub conflicts ### Ben Baumer ### SDS 192Oct 9, 2020(
http://beanumber.github.io/sds192/lectures/mdsr_workflow_02-ghconflicts.html
) --- class: center, middle, inverse ![](https://media.giphy.com/media/8hFJfKMGbbwCQ/giphy.gif) --- ## Goal: Buttermilk fried chicken .pull-left[ ![](https://valleyadvocate.com/wp-content/uploads/2015/02/VA08-MenuFeature1.jpeg) ] .pull-right[ -
You are shopping at Stop & Shop -
Your collaborator is shopping at Big Y -
You only need one of each item - You can't see what the other person has bought until they leave the store ] .footnote[http://cocoandthecellarbar.com/] --- ## Metaphor -
`git add`: put an item in your shopping cart -
`git commit`: pay at the register -
`git push`: leave the store and send updates to collaborators -
`git pull`: sync your shopping list with your collaborators (doesn't happen automatically) --- ## Three typical errors - Can't push because repo is ahead - Can't pull because uncommitted changes - Merge conflict --- ## 1. Push rejection ``` $ git push To https://github.com/YOU/REPO.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/YOU/REPO.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. ``` .footnote[https://happygitwithr.com/push-rejected.html] - Problem: `git` is confused because you are trying to push but you don't have the latest stuff that someone else put in the repository. -- - You are trying to leave the store but your collaborator has already updated the shopping list and you don't know that yet. You might have bought two of the same item. -- -
Solution: pull, then push --- ## 2. Uncommitted changes .footnote[https://happygitwithr.com/pull-tricky.html] ``` $ git pull error: Your local changes to the following files would be overwritten by merge: foo.R Please commit your changes or stash them before you merge. Aborting ``` - Problem: `git` is confused because you made changes but you didn't commit the changes, and now you're trying to pull and it doesn't know if you want to overwrite your changes with someone else's changes. -- - You put something in the cart, but you haven't yet paid for it. You're trying to update your shopping list, but your collaborator has already bought one of the items in your cart. **Do you want to buy another one or put it back on the shelf?** -- -
Solution: commit or revert, then pull, then push --- ## 3. Merge conflict ``` $ git pull Auto-merging foo.R CONFLICT (content): Merge conflict in foo.R ``` .footnote[https://happygitwithr.com/git-branches.html#dealing-with-conflicts] -- > The first thing to do is **NOT PANIC**. Merge conflicts are not the end of the world and most are relatively small and straightforward to resolve. -- - Problem: You and your collaborator changed the same part of the same file in two different ways. `git` doesn't know which one you prefer. -- - Problem: You and your collaborator bought two different kinds of ice cream. You have to tell `git` which one you want, or **how you want to combine them.** -
: resolve conflicts manually (in text editor), then commit, then push --- ## Resolving merge conflicts - If you have this... ```r <<<<<<< HEAD:mp2.Rmd babynames %>% filter(name == "Benjamin") ======= babynames %>% filter(name %in% c("Ben", "Benito")) group_by(name) >>>>>>> issue-5:mp2.Rmd ``` - Make it look like this: ```r babynames %>% filter(name %in% c("Benjamin", "Ben", "Benito")) group_by(name) ``` -- -
: Then commit, then push --- ## GitHub issues -
Like a collaborative task list -- - Use Issues to keep track of who is doing what -- - Minimize potential for merge conflicts by: - Working on different parts of the file - Making small commits - Committing and pulling frequently -- - Read this: (https://guides.github.com/features/issues/)