Skip to content

Instantly share code, notes, and snippets.

@jeremyharris
Created May 10, 2012 15:55
Show Gist options
  • Save jeremyharris/2654088 to your computer and use it in GitHub Desktop.
Save jeremyharris/2654088 to your computer and use it in GitHub Desktop.

Revisions

  1. Jeremy Harris created this gist May 10, 2012.
    56 changes: 56 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    # This is a handful of git commands I use on a daily basis, some of
    # which are pretty basic, some of which took a little research to
    # figure out how to do (so hopefully this is a time saver). It's
    # by no means an exhaustive list as git is really freaking robust.

    ########################
    # logs
    ########################

    # unmerged differences between dev and master (not including extra master commits)
    $ git log master...dev

    # unmerged differences between dev and master (including extra master commits)
    $ git log master..dev

    # nice visual changelog (thanks @jperras)
    # add this alias
    $ git config --global alias.lg "log --decorate --stat --graph --pretty=format:'%C(yellow)%h%Creset (%ar - %Cred%an%Creset), %s%n'"
    # then from now on
    $ git lg

    ########################
    # working
    ########################

    # amend last commit
    $ git commit --amend

    # stash changes for later (use -u to store files not in the index)
    $ git stash save "Working on this feature"

    # view a diff of that stash
    $ git show stash@{0}

    # store portions of a changed file in the index
    $ git add -p

    # remove portions of a changed file from the index
    $ git reset -p

    # after deleting or renaming a ton of files, remove them all from the index
    $ git rm `git ls-files -d`

    # view a diff of files in the index
    $ git diff --cached

    ########################
    # branches
    ########################

    # create and checkout a new branch
    $ git checkout -b newbranch

    # remove a branch (locally and remotely)
    $ git branch -d newbranch
    $ git push origin :newbranch