2  Common Commands

2.1 Git Commands

Command Description
git add --all stage ALL files that have been changed/added/deleted
git add FILE Stage a specific FILE
git branch -av View all of the branches (local and remote)
git checkout -b BRANCH Create a new BRANCH and switch to that BRANCH
git checkout BRANCH Switch to a specific BRANCH
git checkout FILE Revert FILE to most recent commit on local repo
git commit -m 'MESSAGE' Commit changes with short MESSAGE
git diff --stat --cached origin/BRANCH List of files that have been commited (list of files that will be included in next git push)
git diff FILE View changes for a specific FILE; if you just use git diff all changes for all files will be shown. If you have a lot of changes it will end with an (END) on the screen, to quit this screen press the Q key
git fetch --prune origin Fetch branches from origin and prune branches
git fetch origin BRANCH See if there are any changes/updates from a specific BRANCH; could do this prior to git pull
git log -NUMB View a list of the most recent NUMB commits; e.g. git log -2 will show 2 commits
git pull origin BRANCH Pull from specific BRANCH
git push --set-upstream origin BRANCH Push to remote and set upstream
git push origin BRANCH Push to specific BRANCH
git remote prune origin Prune all stale branches from origin
git reset Undo git add; will un-stage all files; can also use git reset FILE to unstage specific file
git status see which files have been changed/added/deleted on working branch

What if I want to ignore any differences on my clone and ‘reset’ to the version on GitHub?

  1. git fetch origin BRANCH
    This will get the most recent versions from GitHub
  2. git reset --hard origin/BRANCH
    This will change all files in your clone repository to match the most up-to-date version from GitHub

This should be done rarely because any changes you have worked on will not be saved.

2.2 UNIX

In addition to git command, you can use UNIX commands in the bash window.

Command Description
cd .. Move up one folder; e.g. go from C:/Documents/FOLDER to C:/Documents
cd FOLDER Move down into a specific folder; e.g. go from C:/Documents to C:/Documents/FOLDER
ls -l View files in current folder and their recent mondification