Merging vs Rebasing, Handy Efficiencies, and Getting out of a Jam
Git is key to many developers’ workflows. Unfortunately, many developers only know enough to get by. Additionally, because Git does not have an obvious mental model or intuitively-named commands, developers often struggle, sometimes badly. Given how powerful Git is - and the tremendous abilities it offers to those who understand - this is sad! To address this, this class will cover merge vs rebase, three uses of rebase, setting up an external editor, and getting out of a jam: reflog, reset, and cherry-pick.
What you'll learn-and how you can apply it
- Learn the differences, advantages, and disadvantages of merge and rebase
- Intelligently converse on why you should choose merge or rebase
- Interactively rebase, i.e. squash commits
- Set up an external editor
- Rebase a local branch onto another local branch
- Update a local branch from a remote branch using rebase
- Move forward, backward, or sideways in time to get out of a jam or just to use Git to its full creative potential
This training course is for you because...
- You can navigate your local repo with ease (git add, git commit, git checkout, etc) but you aren’t so sure about interacting with other repos.
- You want to be able to contribute to discussions on which workflow your team should use and/or how to tweak or improve your current workflow.
- You want to understand merge vs rebase.
- You want to become more efficient, faster.
- You want to become so good at Git that you don’t even think about it anymore; it is after all, only a facilitative element.
- You want to know how to get yourself out of a jam.
- Must know the concept of a repo.
- Must know these basic Git commands: git add, git commit, git checkout, git branch, git fetch, git pull, git push.
- Must be comfortable using Git in command-line interface because we will not be using a graphical user interface.
- Must know a handful of basic command-line interface commands such as “cd”.
Course Set-up: - Git should be installed - An IDE should be installed - This course is tailored for those on Macs. If on Windows, the concepts will still apply. - Set up your repo following these instructions: https://github.com/amandaol/gitClass/wiki
Git Essentials Live Lessons (video)
About your instructor
The timeframes are only estimates and may vary according to how the class is progressing
Segment 1: Overview and Repo Setup Length 20 min
- Instructor will describe her personal motivation for learning/conquering these concepts and lay out what the class will cover, and will then help everyone get their repo setup for use during class.
- Participants will (hopefully) be inspired to get into the content and will know the sequence of topics.
Segment 2: Merge Length 10 min - Instructor will present the model model behind merge. - Participants will understand what’s happening “under the hood” when merging.
Segment 3: Rebase Length 30 min
- Instructor will present the model model behind rebase.
- Participants will understand what’s happening “under the hood” when rebasing.
- Instructor will present the Golden Rule Exercise: add a few commits, run git merge, run git rebase, compare
Segment 4: Rewriting History Length 10 min
- Instructor will present the primary controversy behind rebasing, step through it, put it in perspective, and encourage an entirely different and more healthy/significant perspective.
- Participants will learn lose any concern they had over rewriting history, will lose any moral sense about these things, and will instead recognize that Git is just a tool (not a matter of right and wrong) and recognize the significance of asking the “better question” which is “what story do you want master to tell?”
Segment 5: Three Uses of Rebase: Interactive Rebase + Efficiency: Set up an External Editor Length 25 min
- Instructor will present three uses of rebase, the first of which is an interactive rebase. Directly after this, instructor will demo this which will make it very clear why you would want to set up an external editor. This will be followed by setting up an external editor.
- Participants will learn the first of three uses of rebase plus an efficiency, that of setting up an external editor
Exercise: set up an external editor
Segment 6: Three Uses of Rebase: Local rebase Length 10 min
- Instructor describe/present and demo a local to local rebase.
- Participants will learn the second of three uses of rebase.
Exercise: local to local rebase
Segment 7: Three Uses of Rebase: Remote to local rebase Length 10 min
- Instructor describe/present and demo a remote to local rebase.
- Participants will learn the third of three uses of rebase.
Exercise: remote to local rebase
Segment 8: Full Life Cycle Incorporating Rebase Length 15 min
- Instructor will present a scenario where two of uses of rebase are used to achieve a particular goal in a given workflow, and will discuss her own daily workflow and use of rebase.
- Participants will observe that rebase and merge can be used together in the same workflow, will learn that multiple uses of rebase can be best, and will hopefully conclude that once a workflow is known it and should be very, very easy and reliable.
Exercise: try out all steps just described
Segment 9: How to Get Out of a Jam Length 25 min
- Instructor will present how to get out of a jam using reflog, reset, and cherry-pick
- Participants will lose any concern over losing committed work, will gain confidence in Git and will hopefully be encouraged to try out more things in their code knowing “Git has their back”, and will learn how to get out of a jam.
Exercise: use git reflog, reset, and cherry-pick to move around in time in your repo