Skip to content

Some simple exercises to demonstrate git in everyday workflow

Notifications You must be signed in to change notification settings

tall-dan/gitting_better

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Gitting Better

We use git everyday, but sometimes forget that there's more than just push & pull

Git Core

  • 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

Getting started

  • Fork this repo!
  1. Question 1: Look at the initial commit in the repo. What's it's parent?
  2. Create a new branch, call it something creative like new_branch_<your_name>
  3. Push it up to your remote.
  4. Add a file in new_branch, called new_file.txt, and push it up. Take note of the commit sha
  5. Question 2: How do you find a commit's sha from the command line? in git ui?
  6. Oops! You meant to put something in new_file.txt. echo 'hello' > new_file.txt
  7. You don't want everyone to know how dumb you are
  8. Question 3: How do you fix your dumb commit without anyone knowing?
  9. Is the sha from your fixed commit the same as the on from your dumb commit?
  10. Let's play with merge conflicts
  11. Checkout conflicted_branch.
  12. Try to create a pull request to your master. Note that it won't merge, because there are merge conflicts
  13. Rebase to the rescue!! git rebase <upstream>/master, where is probably something like [upstream, origin]
  14. 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
  1. What about amending multiple commits?

  2. 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.

  3. Checkout the branch terrible_commit_history

  4. Look at the history

  5. Rewind to a point before your (my) terribleness started

  6. Consolidate to commits that make sense

  7. Push em up

  8. You've discovered that your project collaborators can't push commits to new_branch, because it's on your remote.

  9. Question 4: How do you 'move' a branch from your remote to a different one?

Credit where it's due

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 ;)

About

Some simple exercises to demonstrate git in everyday workflow

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published