Cheatsheet

Basics:

  1. Adding files
  • You can add files individually like:
    $ git add <file_name>
  • You can add files in bulk like:
    $ git add --all
  1. Creating commits: Commits are (semi)-immutable snapshots in time that should represent the state of the codecase at the point. A commit does not have to be functional; you should commit frequently so you can backtrack if you get into trouble.
$ git commit -m 'My descriptive commit message'

Or use your favorite text editor (Vim by default):

$ git commit
  1. Pushing
$ git push origin <branch_name>
  1. Branching

When you branch, your branch will be created FROM the commit/branch you're currently on, not HEAD.

$ git checkout -b <new-branch-name>
  1. Merging

You can merge on the command line if you want to merge two feature branches together, or update your branch with changes to master. From the branch you want to merge INTO, simply run:

$ git merge --no-ff <other-branch>

Sometimes you'll encounter conflicts when merging. Simply resolve them, then run:

$ git merge --continue

If at any point you get stuck in a bad merge with a lot of conflicts, you can abort the merge:

$ git merge --abort
  1. Rebasing

Rebasing is like merging, but you "replay" your commits onto a branch as if they happened from a different HEAD. From your feature branch:

$ git rebase <other-branch>

It's easy to get into conflicts with rebasing. See this guide for helpful pointers