Skip to content
krivard edited this page Mar 14, 2016 · 1 revision

Are you new to git? Are you confused or anxious about making a mistake? This page is for you!

First, git is legitimately a complex, sophisticated tool, and it's okay to find it baffling!

This is my favorite cheatsheet: http://ndpsoftware.com/git-cheatsheet.html

I like it because it establishes 5 buckets where concepts reside, notably the separation between the workspace, the index, and the local repository. It also frames commands as transferring information between two buckets, which is a useful mental model. Especially if your goal is to avoid or be the person listed in the XKCD alttext above.

I'm going to start keeping an eye on my git habits, and will paste snippets of useful tasks below. The command line logs were produced with the raw history command in bash, and list the line number followed by the command. I've annotated each line with an explanation of what I was trying to do. Hopefully, that will help you figure out the "commands that will fix everything" if you've gotten yourself into a tangle.

Questions & requests to krivard@cs!

Feature development in a branch

  728  git checkout -b adagradNormalize                  # create a new branch and switch to it
  729-747 ...                                            # make changes to code (Eclipse) and run tests
  748  git status -uno                                   # show changed files, ignoring (u)ntracked files
  749  git add adagrad.properties                        # add changes from a file to the index
  750  git add ../webkb/Makefile                         # same
  751  cd ../../                                         # move to a more convenient place in the directory tree
  752  git status                                        # what changes haven't I added yet?
  753  git status -uno                                   # whoops, don't tell me about untracked files
  754  git add conf/log4j.properties src/java/           # add changes from some files to the index
  755  git status -uno                                   # check staged changes for gremlins/stowaways/unwanted files
  756  git commit -m "Removed Adagrad-specific trainer"  # commit staged changes
  757  git checkout working                              # switch to working branch
  758  git merge adagradNormalize                        # apply branch's changes to working branch & commit them