When I was getting started with git,  I developed a “greatest hits” of commands and ideas that helped me understand what was going on. Here are a few of them — more to be added.

  1. Whatever else you do, remember that commits are forever! If you make a mistake, don’t think of it as ‘deleting’ the commit. You’re just pushing a new commit with new code that cancels out the old commit’s work. The more comfortable you are with this though, the better — for reverting, cherry picking, etc.
  2. Change the name of a commit you just made: git commit --amend
  3. Cherry pick a set of commits: git cherry-pick A^..B where A is the oldest commit you want and B is the newest. This is inclusive! If you want A through B excluding A and B, just use A..B.
  4. Undo your last commit (only if you haven’t pushed!!): git reset HEAD~
  5. Undo a commit you already pushed: git revert commit_name
    1. Never use rebase on a commit that’s already been pushed especially in a shared repository! Rebase rewrites history, and that’s not clean, sustainable, or kind to your teammates 😉
  6. To bring your feature branch up-to-date with a base branch (e.g., develop or master):
    1. git checkout develop
    2. git pull
    3. git checkout feature/your_feature_branch
    4. git merge --no-ff develop
  7. To remove untracked files, use git clean -f. Add the -d tag if you want to remove untracked directories as well.
  8. Don’t revert merge commits! This is a fast way to mess up your history. Reverting a bunch of individual commits can seem like a pain, but it takes less time than trying to undo a merge reversion.
  9. This is also a great resource for undoing (almost) everything in Git.

More later!