We use git everyday, but sometimes forget that there's more than just push & pull
- Commit: code changes + parents + who dunnit + why
- ref: just a reference
- HEAD: ref to current commit
- branch: named reference to some commit
- tag: named reference to some commit
- remote: repository where you'll look for commits
- Fork this repo!
- Question 1: Look at the initial commit in the repo. What's it's parent?
- Create a new branch, call it something creative like
new_branch_<your_name>
- Push it up to your remote.
- Add a file in new_branch, called new_file.txt, and push it up. Take note of the commit sha
- Question 2: How do you find a commit's sha from the command line? in git ui?
- Oops! You meant to put something in new_file.txt.
echo 'hello' > new_file.txt
- You don't want everyone to know how dumb you are
- Question 3: How do you fix your dumb commit without anyone knowing?
- Is the sha from your fixed commit the same as the on from your dumb commit?
- Let's play with merge conflicts
- Checkout
conflicted_branch
. - Try to create a pull request to your master. Note that it won't merge, because there are merge conflicts
- Rebase to the rescue!!
git rebase <upstream>/master
, where is probably something like [upstream, origin] - When you've successfully rebased, your git history should now look like
aa579eff8c13acfe3cefc3e75ed47ec543337f88 conflict it real good
4569fc69957f46c3dd1640d60def299883c070b2 Merge pull request #1 from schepedw/readme_gooder
0ef3f33870d4ee26291053fd5ae6249003c027f2 readme real gooder
c5eee65a95c3f012bdcf46d0b7df47a2c37c7f78 beginning of readme
-
What about amending multiple commits?
-
Maybe you're bad at committing. Maybe you put 'wip' as your commit messgae 9x in a row. Either way, it's time to make things prettier.
-
Checkout the branch
terrible_commit_history
-
Look at the history
-
Rewind to a point before your (my) terribleness started
-
Consolidate to commits that make sense
-
Push em up
-
You've discovered that your project collaborators can't push commits to new_branch, because it's on your remote.
-
Question 4: How do you 'move' a branch from your remote to a different one?
These exercises come from a lecture Kyle Hargraves gave at Enova 4/15/15. You can find the slides here if you're an Enova employee. Otherwise.. well, we're probably hiring ;)