Dale's Git Command Notes

Note: These are my online notes and a work in progress. They're public so I can grab them anywhere, if others find them useful all the better. Caveat emptor, I'm just learning this stuff.


git config --list List all your configuration

Creating Repositories

git init Make a Git repository that manages the existing working directory.
git --bare init Make a "bare" Git repository. It does not manage the directory it resides in. Used for creating remote repositories to push updates to.

Managing Files in a Branch

git status Displays the current branch and the status of the files in the current working directory. Files can be in one of three states: untracked, modified, commit-candidate (changes to be committed).
git diff Produces a diff of the files that have changed but haven't been add to the next commit.
git diff --cached
git diff --staged (> v1.6.1)
Produces a diff of the files that have been added to the next commit.
git add {filename/wildcard} Tell Git that an untracked or modified file is now a candidate for the next commit. In the jargon, move the file(s) to "staging area".
git rm {filename/wildcard} Remove file(s) from current branch. Will also delete the physical file.
git rm --cached {filename/wildcard} Remove file(s) from revision control but doesn't delete the physical file. Handy if a file was accidentially added to revision control.
git mv {current-file-name/path} {new-file-name/path} Move or rename a file.
git commit -m 'Hopefully useful message' Commit the candidate files -- files added to the staging area with git add -- to the current repository branch.
git commit -a -m 'Hopefully useful message' Commits staged files and automatically git adds all other modified files to the commit. Untracked files remain excluded from the commit.

Managing Branches

git branch Show the branches in this repository with a star ("*") beside the current branch.
git branch {new branch name} Creates a branch of the specified name. Note: It does not automatically switch you to that branch. You must use checkout the new branch if you want to use it right away.
git checkout {existing branch name} Switches you to the specified branch.
git checkout -b {new branch name} Creates a new branch and automatically switches to that branch. It is the equivilent of:
   git branch {name}
   git checkout {name}
git branch -d {branch} Delete the specified branch.
git branch -r Show remote branches. Branches available for checkout won't show automatically after a clone.
git log Show the list of commits on the branch
git log --name-status
git log --name-only
git log --stat
List the commits and include a list of files that have changed. The 3 options give slightly different kinds of information.

Merging Branches

git merge {branch} Merges the specified branch into the currently checked out branch.

Remote Repositories

git clone {url} Create a local copy of the repository at {url} and automatically link the two. With git clone Git will automatically give the remote repository the name 'origin'.
git remote [-v] List the remote repositories the local repository knows about.
git remote show [{remote-name}]
git remote show origin
Shows information about the remote such as URL, branches, and how remote/local branches are mapped.
git fetch [{remote-name}] Grabs the remote updates for the current branch but does not merge them. You must do a manual merge.
git pull [{remote-name}] Grabs the remote updates for the current branch and merges them into the current branch.
git push {remote-repo-name} {remote-branch-name} Pushes the current branch to the specified git remote giving it the specified name.


Multiple Remote Masters Written from the persective of a specific host but generally applicable anywhere.