Skip to content

Instantly share code, notes, and snippets.

@adamburvill
Last active August 29, 2015 13:58
Show Gist options
  • Save adamburvill/9944356 to your computer and use it in GitHub Desktop.
Save adamburvill/9944356 to your computer and use it in GitHub Desktop.
Useful Git Commands

Add all files to staging

    git add .

Check differences in file across commits

    git diff SHA-HASH FILENAME

Git UI

    gitk

Logging

Git Log Extra Statistics

    git log --stat

Git Log Brief Version

    git log --oneline

Graphical Log Representation of all branches, decorated for colour/branch name

    git log --oneline --graph --all --decorate

Branches

Get list of current branches (create new branch)

    git branch (optional branch name)

Create and checkout a branch at same time

    git checkout -b BRANCH-NAME

Delete a branch

    git checkout -d BRANCH-NAME

Merging

Basic merge

    git merge BRANCH-NAME

Rebasing (takes secondary branch and plays it "into" the master branch by rewinding HEAD)

    git rebase SECONDARY-BRANCH-NAME

Advanced Features

Interactive Add Mode (patch/revert/diff etc, can commit hunks of code in a single file)

    git add -i

Short to Patch Mode

    git add -p

Stash Command (Apply will take latest stash and apply changes to WD with optional stash number, List shows files, Save does an imitation commit on the stash)

    git stash / git stash apply stash@{1} / git stash list / git stash save "save message"

Stash Pop - removes stash from stash directory and adds it to current WD

    git stash pop stash@{1}

Aliasing

Creating terminal aliases

    alias my_alias='git log --oneline --all --graph'

Git Alias (creates alias of 's' for git status etc)

    git config --global alias.s status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment