git Frequently Asked Questions

By Xah Lee. Date: . Last updated: .

What is git {origin, master, object, index}?

origin
The default upstream repository. Most projects have at least one upstream project which they track. By default origin is used for that purpose. New upstream updates will be fetched into remote remote-tracking branches named origin/name-of-upstream-branch, which you can see using git branch -r.
master
Whenever you create a git repository, a branch named “master” is created, and becomes the active branch. [see Git Branching]
index
(aka staging area) A collection of files with stat information, whose contents are stored as objects. The index is a stored version of your working tree. Truth be told, it can also contain a second, and even a third version of a working tree, which are used when merging.
object
The unit of storage in git. It is uniquely identified by the SHA1 of its contents. Consequently, an object can not be changed.
object database
Stores a set of objects, and an individual object is identified by its object name. The objects usually live in $GIT_DIR/objects/
object name
The unique identifier of an object. The hash of the object’s contents using the Secure Hash Algorithm 1 and usually represented by the 40 character hexadecimal encoding of the hash of the object.
pack
A set of objects which have been compressed into one file (to save space or to transmit them efficiently).

See: git help glossary

What is the difference between clone and checkout

git clone is for getting a new repository from a remote git server.

git checkout is to checkout from a older commit or different branch to your local repository. Use option “-f” (force) to discard any changes you made in your working directory.

You can call git log first to get a list of commit ID. Then use git checkout -f commitID to update your local repository (if you want to look at old version of files). Then, git checkout -f master to revert back to your current state.

# example of git checkout old commit
git checkout -f 9890e063897b2f7f40c31af513b3f1ada243915f
# example of making local git branch the master branch
git checkout -f master

Move and Rename File

You shouldn't need to rename or move files. Just use normal unix/OS commands {rm, mv} to {delete, rename, move} files in your working directory. Then, when you are ready to git, do git add -A. The “-A” option will {add, remove} all {new, deleted} files based on your working dir, then you can git commit -m"…".

but if you really want to rename or move, you can do

git mv fileOldName fileNewName

Thanks to [Nick Alcock https://plus.google.com/115849739354666812574/posts] for many tips.

Work with git repo without cd into the dir

use option

--git-dir=path/.git/

Example:

git --git-dir=/Volumes/backup/web/.git/ pull /Users/joe/web/

Display date in ISO format

git log --date=iso

git is there any tech consequence of not setting name and email? i.e. does it prevent push or something?

Name and email is an enforced convention. You’re supposed to attribute your commits, otherwise collaborators won’t make sense of who did what. The official Git binary does not let you commit unless you have set at least user.email OR it can make a reasonable guess at your email (example: if you have a fully-quailified host name set, it will take your <username>@<hostname.domain>).

Git itself does not actually use the emails for any purpose, so, technically, this convention can be circumvented, by creating commit objects programmatically. e.g. git-svn maps Subversion user names to <username>@<guid of svn repository> unless otherwise instructed.

—Yuri Khan , from @ https://plus.google.com/u/0/+XahLee/posts/2swUrf372Ar

git FAQ

git

git FAQ