Command quick reference (very good one):
http://jonas.nitro.dk/git/quick-reference.html
command line help:
git help [some command]
https://nvie.com/posts/a-successful-git-branching-model/
git add path - will recursive add everything down the path
git rm - remove the files
It's simply a directory, only at the root dir has a ".git" dir, better than cvs
Initiate a dir as reposit:
git init : create a repository in current dir
git clone url : clone a remote repository into a subdirectory
See http://git-scm.com/book/it/v2/Git-on-the-Server-The-Protocols
samples:
ssh://user@server:/path/from/root/project.git
This will pay off, it will save a lot effort. refer to https://help.github.com/articles/ignoring-files
(1) create .gitignore file, check into the repository if wish; can also uses a global rule, see reference above
(2) write some rules: "#" is comment, "*.exe" specify the file
(3) ! reverse the ignore instruction, so "*.jason" followed by "!spec/*.jason" makes .jason ignored in other dir but not spec
(4) .gitignore put in a dir only affects that dir, so to achieve dir specific control
git status
Where nothing changed:
# On branch master
nothing to commit (working directory clean)
Where something changed, and not staged for commit:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: index_html_v2.html
#
no changes added to commit (use "git add" and/or "git commit -a")
Where things changed and staged for commitment:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: index_html_v2.html
#
Find status recursively
find .|grep -v -e "\.git"|while read name;do git status -s $name;done
Compare (diff)
diff with master branch 1 commit away
git diff master~1:src/main.c src/main.c
diff between two commits
git diff master be3901a7d87a39e636069c4acc45d59109794f6b
git log
List directory:
git ls-tree -r --name-only c8a8c86896dcef2c2b320cac6e53512600d3bc17
If no output, the current directory maybe not exist in the earlier version.
Check file content:
git show HEAD@{2013-02-25}:./fileInCurrentDirectory.txt
git show HEAD~4:src/main.c
git show b2f8be577166577c59b55e11cfff1404baf63a84:./flight-simulation/src/main/components/nav-horiz.html
http://stackoverflow.com/questions/4114095/revert-git-repo-to-a-previous-commit
To obtain the remote url from github, login and copy the url on the web interface of the project (choose http, ssh or read-only), then add the url to the local repository and push to server as follows:
(1) git remote add [<options>] <name> <url>
(2) git push -u <name>
Note:
(1) <name> is usually "origin"
(2) <url> - use http url from github; choose http, ssh or read-only
(3) if there's conflict requires merging, push will fail and suggestion shown
Choosing http or ssh:
(1) choose http, whenever push git will ask username and password
(2) choose ssh, register public key in ~/.ssh/id_rsa.pub with git person profile; then no password asked again
Solving Conflict:
(1) git pull
(2) if automatic merge fail, manually edit the file to solve conflict
Show remote status:
git remote show [origin]
git remote update
References: git-scm.com/book/en/Git-on-the-Server | http://aoingl.iteye.com/blog/1365201
"It generally takes a tiny amount of resources and rarely need to use an entire server for it."
Bare repository - it has no working directory and just data. "In the simplest terms, a bare repository is the contents of your project's .git directory and nothing else".
Server setup is simple. Complication comes from user management for large group.
Setup
(1) Choose communication protocol
Available protocols: Local (just another directory), SSH, Git (similar to SSH with absolutely NO AUTHENTICATION), http/s
SSH is most commonly used. Others see http://git-scm.com/book/en/Git-on-the-Server-The-Protocols
For remote server with non-standard port, do this at local:
Put something like this in your .ssh/config:
Host githost
HostName git.host.de
Port 4019
User renbing
(2) User management (SSH)
Option 1: set up accounts for everyone
Option 2: set up single 'git' user and add everyone's public key to the ~/.ssh/authorized_keys, see here and here.
sudo adduser git
su git
cd
mkdir .ssh
touch .ssh/authorized_keys
chmod 700 .ssh
chmod 640 .ssh/authorized_keys
add some entries to ~/.ssh/authorized_keys
try to logon as git without password
change user git's shell from '/bin/sh' to '/usr/bin/git-shell' (vim /etc/passwd)(DO NOT use "nologin" shell, must use git-shell)
authenticate from centralized authentication source such as LDAP
(3) Preparation for the server
Just install 'git-core' and done
(4) Initiate a new remote repository
This consists of initializing a bare repository on server, initializing a repository locally, then make a first commit and push local to server. See http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server.
I have created a script for doing this, see attachment to this page.
(5) Put a local repository onto server
create a bare clone ("git clone --bare your_repository your_repository.git")
copy the .git dir to server with scp
now the repository can be used (it can be cloned, then use to push / pull)