This appendix provides an alphabetical list of the Git commands cited in this Web page, along with brief descriptions of what the commands do.
Note that you may always use either ‘git help command’ or ‘git command --help’ to get short, man-page style help on how to use any given Git command.
git add
Add a file to the list of files to be committed.
git branch
View existing branches, or delete a branch. The most useful options are -a and -d.
git checkout
Checkout an existing branch, create a new branch, or checkout a file to reset it. Use the -b option to create and checkout a new branch in one operation.
git clone
Clone (make a new copy of) an existing repository. You generally only need to do this once.
git commit
Commit changes to files which have been staged for committing with ‘git add’. This makes your changes permanent, in your local repository only. To publish your changes to an upstream repo, you must use ‘git push’.
git config
Display and/or change global and/or local configuration settings.
git diff
Show a unified-format diff of what’s changed in the current directory as of the last commit. It helps to have Git configured to use its builtin pager for reviewing diffs (see Configuring Global Settings For Git).
git difftool
Use a “tool” (usually a GUI-based program) to view differences, instead of the standard textual diff as you’d get from ‘git diff’.
git fetch
Update your local copy of the upstream’s branches. That is, update the various ‘origin/’ branches. This leaves your local tracking branches unchanged. With the --prune option, this removes any copies of stale ‘origin/’ branches.
git format-patch
Create a series of patch files, one per commit not on the original branch from which you started.
git gc
Run a “garbage collection” pass in the current repository.
This can often reduce the space used in a large repo. For
gawk
it does not make that much difference.
git help
Print a man-page–style usage summary for a command.
git log
Show the current branch’s commit log. This includes who made the commit, the date, and the commit message. Commits are shown from newest to oldest.
git merge
Merge changes from the named branch into the current one.
git pull
When in your local tracking branch xxx
,
run ‘git fetch’, and then merge from origin/xxx
into xxx
.
git push
Push commits from your local tracking branch xxx
through origin/xxx
and on to branch xxx
in the upstream repo. Use ‘git push -u origin --delete xxx’ to delete
an upstream branch. (Do so carefully!)
git rebase
Rebase the changes in the current purely local branch to
look as if they had been made relative to the latest
commit in the current upstream branch (typically master
).
This is how you keep your local, in-progress changes up-to-date
with respect to the original branch from which they were started.
git reset
¶Restore the original state of the repo, especially with the --hard option. Read up on this command, and use it carefully.
git stash
¶Save your current changes in a special place within Git. They can be restored with ‘git stash pop’, even on a different branch. Use ‘git stash list’ to see the list of stashed changes.
git status
Show the status of files that are scheduled to be committed, and those that have been modified but not yet scheduled for committing. Use ‘git add’ to schedule a file for committing. This command also lists untracked files.