A little cheat sheet of common commands to help you become a Git pro.

  • setup
    git init

    Initialize an existing local directory as a Git repository

  • setup
    git clone [url]

    Retrieve an entire repository from a hosted location (Github, Bitbucket, etc.) via URL

  • stage
    git status

    Show modified files in the local, working, directory

  • stage
    git add [file]

    Add a particular file to your next commit (stage)

  • stage
    git add .

    Add all files to your next commit

  • stage
    git reset [file]

    Unstage a file while retaining the changes in local directory

  • stage
    git diff

    See changes to your unstaged files

  • stage
    git diff --staged

    See changes to staged, but uncommited, files

  • stage
    git commit -m “[descriptive message]”

    Commit your staged content as a new commit snapshot

  • branch
    git branch

    List your branches. An asterik (*) will appear next to the active local branch

  • branch
    git branch [branch-name]

    Create a new branch at the current commit

  • branch
    git checkout [branch]

    Switch to another branch and check it out into your local, working, directory

  • branch
    git merge [branch]

    Merge the specified branch’s history into the current one

  • inspect
    git log

    Show the commit history for the currently active branch

  • inspect
    git log --follow [file]

    Show the commits that changed file, even across renames

  • inspect
    git diff [branchB]...[branchA]

    Show the diff of what is in branchA that is not in branchB

  • inspect
    git show [SHA]

    Show any object in Git in human-readable format

  • inspect
    git blame [file]

    See who changed what and when they did it in a particular file

  • tracking
    git rm [file]

    Delete the file from your project and stage the removal for commit

  • tracking
    git mv [existing-path] [new-path]

    Change an existing file path and stage the move

  • tracking
    git log --stat -M

    Show all commit logs with indicators of any paths that have moved

  • share
    git remote -v

    See a list of all configured remote repo URLs

  • share
    git remote add [alias] [url]

    Add a git URL as a remote alias

  • share
    git remove rm [alias]

    Remove a remote alias from your project

  • share
    git fetch [alias]

    Fetch down all the branches from a specified remote URL

  • share
    git merge [alias]/[branch]

    Merge a remote branch into your current branch to bring it up to date

  • share
    git push [alias] [branch]

    Push local branch commits to the remote repository branch

  • share
    git pull

    Fetch and merge any commits from the tracking remote branch

  • rewrite
    git rebase [branch]

    Apply any commits of current branch ahead of specified one

  • rewrite
    git reset --hard [commit]

    Clear staging area, rewrite working tree from specified commit

  • stash
    git stash

    Save modified and staged changes

  • stash
    git stash --include-untracked

    The same as a regular stash, but saving your untracked files too

  • stash
    git stash list

    List stack-order of stashed file changes

  • stash
    git stash apply

    Resume working on the stash at the top of your stash list while keeping the stash intact.

  • stash
    git stash pop

    Resume working on the stash at the top of your stash list and delete the stash.

  • stash
    git stash drop [stash-id]

    Delete a specific stash

  • stash
    git stash clear

    Delete all stashes