.git/objects/ : real repository data (identified by SHA-1) .git/refs/ : references to objects (heads of development, revision tags)
.git/HEAD : Master head : points to default branch .git/index : describes your current working tree
# RQ : objects are immutable git cat-file -t 557db03de997c86a4a028e1ebd3a1ceb225be238 : gives the type of the file git cat-file blob 557db03de997c86a4a028e1ebd3a1ceb225be238 : gives the content of the file
diff-tree
+----+
| |
| |
V V
+-----------+
| Object DB |
| Backing |
| Store |
+-----------+
^ ^
| |
| | diff-index --cached
| |
diff-index | V
| +-----------+
| | Index |
| | "cache" |
| +-----------+
| ^
| |
| | diff-files
| |
V V
+-----------+
| Working |
| Directory |
+-----------+
# git config --global user.email "user@domain" # git config --global user.name "firstname lastname"
# mkdir test && cd test # git init
# echo "Hello World" >hello
# echo "Silly example" >example # git update-index --add hello example
# git diff-files : raw summary # git diff : readable differences (= git diff-files -p)
# git diff HEAD (= git diff-index -p HEAD) : differences between a commited tree and the working directory # git diff-index --cached -p HEAD : compares a tree and the index cache content
# git write-tree : Raw way to create a tree
# tree=$(git write-tree) # commit=$(echo 'Initial commit' | git commit-tree $tree) # git update-ref HEAD $commit
# git rm <file> : remove files from index (=git update-index --remove <file>)
# git add <file : add files to index (= git update-index --add <file>)
# git update-index hello example : updates index of files
# git diff : show differences with index
# git diff HEAD : show the differences with a tree (HEAD pointer tree)
# git commit : store a change in the repository, give a commit message !
: all lines beginning with # will be ignored
# git diff-tree -p HEAD : difference between the commited tree and the master tree # git diff-tree -p HEAD --pretty : idem, with metadata of commits
# git tag my-first-tag : light tag (branch put in the .git/refs/tags/ diretory rather than .git/logs/refs/heads) # git diff my-first-tag : diff between the tag and the working directory # git tag -s my-major-tag : real git object, will sign current HEAD # git tag <tagname> <mybranch> : tag from a branch
# git checkout -b <mybranch> : creates a branch (pointer into the Git object database in .git/refs/heads/) # git checkout -b <mybranch> <earlier-commit> : creates a branch from an earlyer commit (tag or branch) # git branch : displays the current branch
# cp -a repo-src repo-dst
# cd repo-dst
# git reset # does :
git read-tree --reset HEAD # total index rebuild
git update-index --refresh # makes sure to match up all index entries with the checked-out files
# git clone git://git.kernel.org/pub/scm/git/git.git/ my-git # cd my-git # git checkout
# git checkout <name> : name can be a branch or a tag
# adduser git # mkdir /pub # mkdir /pub/my-repo.git # chown -R git:git /pub/my-repo.git # su - git # cd /pub/my-repo.git # git --bare init --shared
Gives SSH accces to this directory from the users. Remark : You can use git-shell in order to limit system exposure. As root:
# USERNAME="myuser"
# KEYSDIR="/data/keys"
# adduser --shell /usr/bin/git-shell --ingroup git --disabled-password ${USERNAME}
# mkdir -p ${KEYSDIR}/${USERNAME}
# cd ${KEYSDIR}/${USERNAME}
# ssh-keygen -t rsa -b 4096 -f ${USERNAME}_rsa_4096 -P ""
# mkdir /home/${USERNAME}/.ssh
# cp ${USERNAME}_rsa_4096.pub /home/${USERNAME}/.ssh/authorized_keys
# chmod 700 /home/${USERNAME}/.ssh
# chmod 600 /home/${USERNAME}/.ssh/authorized_keys
# chown -R ${USERNAME}:git /home/${USERNAME}/.ssh
Now send the ${USERNAME}_rsa_4096 file to your new user Ask him to put a passphrase to the key with :
# ssh-keygen -f <keyfile> -p
Ask him to put the file in ~/.ssh/git_<original key file name>
If not already done for the user :
# git config --global user.email "user@domain" # git config --global user.name "firstname lastname"
# export GIT_SSH_COMMAND='ssh -i <private_key_file>' # git clone foo.com:/pub/my-repo.git # cd my-repo
Remark : either do the export each time you use a new shell, either configure the .ssh/config file
# tree=$(git write-tree) # commit=$(echo 'Initial commit' | git commit-tree $tree) # git update-ref HEAD $commit # git push origin master
Do not forget git add/rm/mv
# git diff # git diff -p HEAD # git commit
Or :
# git commit -a
# git pull origin
# git push origin master
Then iterate to 3)