Commands Overview
This section is meant to be a really quick reference to the commands we have reviewed in Git and a quick description of what they do, where we have talked about them and where to find out more information on them.
Basic Git
git config
Sets configuration values for things like your user name, email, and gpg key, your preferred diff algorithm, file formats to use, proxies, remotes and tons of other stuff. For a full list, see the git-config docs
git init
Initializes a git repository - creates the initial '.git' directory in a new or existing project.
git clone
Copies a Git repository from another place and adds the original location as a remote you can fetch from again and possibly push to if you have permission.
git add
Adds changes in files in your working directory to your index, or staging area.
git rm
Removes files from your index and your working directory so they will stopped being tracked.
git commit
Takes all of the changes staged in the index (that have been git add
ed),
creates a new commit object pointing to it,
and advances the branch to point to that new commit.
git status
Shows you the status of files in your index versus your working directory. It will list out files that are untracked (only in your working directory), modified (tracked but not yet updated in your index), and staged (added to your index and ready for committing).
git branch
Lists existing branches,
including remote branches if '-a' is provided.
Creates a new branch if a branch name is provided.
Branches can also be created with '-b' option to git checkout
.
git checkout
Checks out a different branch - makes your working directory look like the tree of the commit that branch points to and updates your HEAD to point to this branch now, so your next commit will modify it.
git merge
Merges one or more branches into your current branch and automatically creates a new commit if there are no conflicts.
git reset
Resets your index and working directory to the state of your last commit, in the event that something screwed up and you just want to go back.
git rebase
An alternative to merge that rewrites your commit history to move commits since you branched off, to apply to the current head instead. A bit dangerous as it discards existing commit objects.
git stash
Temporarily saves changes that you don't want to commit immediately for later. Can re-apply the saved changes at any time.
git tag
Tags a specific commit with a simple, human readable handle that never moves.
git fetch
Fetches all the objects that a remote version of your repository has that you do not yet have, so you can merge them into yours or simply inspect them.
git pull
Runs a git fetch
then a git merge
.
git push
Pushes all the objects that you have that a remote version does not yet have to that repository and advances its branches.
git remote
Lists all the remote versions of your repository, or can be used to add and delete them.
Inspecting Repositories
git log
Shows a listing of commits on a branch or involving a specific file and optionally details about what changed between it and its parents.
git show
Shows information about a git object, normally used to view commit information.
git ls-tree
Shows a tree object, including the mode and name of each node and the SHA-1 value of the blob or tree that it points to. Can also be run recursively to see all subtrees as well.
git cat-file
Used to view the type of an object if you only have the SHA-1 value, or used to redirect contents of files or view raw information about any object.
git grep
Lets you search through your trees of content for words and phrases without having to actually check them out.
git diff
Generates patch files or statistics of differences between paths or files in your git repository, or your index or your working directory.
gitk
Graphical Tcl/Tk based interface to a local Git repository.
git instaweb
Wrapper script to quickly run a web server with an interface into your repository and automatically directs a web browser to it.
Extra Tools
git archive
Creates a tar or zip file of the contents of a single tree from your repository. Easiest way to export a snapshot of content from your repository.
git gc
Garbage collector for your repository. Packs all your loose objects for space and speed efficiency and optionally removes unreachable objects as well. Should be run occasionally on each of your repos.
git fsck
Does an integrity check of the Git "filesystem", identifying dangling pointers and corrupted objects.
git prune
Removes objects that are no longer pointed to by any object in any reachable branch.
git-daemon
Runs a simple, unauthenticated wrapper on the git-upload-pack program, used to provide efficient, anonymous and unencrypted fetch access to a Git repository.