Git‎ > ‎

Quick Reference

The page discussing the Typical Usage of git may be of assistance when you are trying to figure out how to use these commands.

git diff
Show what changed in your working files between the last commit and now.

git add <file1> <file2> ...
Adds changes to a staging area.  You can build a larger commit this way.  One must use git add in order to commit a new file.

git commit
git commit <file1> <file2> ...
Add changes to your repository's history.  If no files are specified, you are committing everything that was staged using git add.  When files are specified, it only commits those files and skips the staged changes.

git pull
git pull <remote>
First does a fetch then does a merge on current branch.  This will be one of the more often used commands.  The fetch and merge commands are described a bit more below.

git push
Takes your history and pushes it into a remote repository.  If you get an error doing this, you probably don't have the remote's history in your own and the usual fix would be to use git pull before you git push changes.

git fetch <remote>
Pulls in changes from a remote repository.  If none is specified, it will fetch history from "origin".

git merge
Merges your change history with another change history.

git branch
git branch -a
Lists all branches on local repository.  When you use -a, it lists all branches and includes all remote repository branches.  Without the -a you will only see local branches.

git cherry-pick -x <commit_hash>
Takes a commit and puts it into another branch.  Using -x will add a line to the commit message indicating the original commit.

git log
git log -p
Gets a list of commits and their messages.  If you add -p at the end, you will get the changes to the files in a "diff" format.

git stash
git stash save "message"
Records the changes you've made but have not yet committed.  Returns the files back to their original state.  Stashes are a good way to save your progress but not commit files, and is useful if you are switching branches or pulling in history from another source.

git stash apply
git stash apply <stash_name>
Applies the most recent or a specific set of changes you've saved back to your working copy of files.  Using apply will still keep the stash saved too; they won't be removed from your list of stashes.