Installation

Debian

# pour debian etch
apt-get install git-core cogito curl
## parfois la sélection avec update-alternatives --config git de /usr/bin/git-scm est nécessaire

# pour debian lenny
apt-get install curl git-core liberror-perl rsync

# pour seahorse/gnome keyring 
# source: from http://stackoverflow.com/a/14528360/3229774 and https://wiki.archlinux.org/index.php/GNOME/Keyring#GNOME_Keyring_and_Git
apt-get install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
make

# en usager:
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring

Information réseau

git:// utilise le port 9418. http:// utilise le port 80.

Checkout d'un projet = clone

Exemple:
git clone git://sflphone.org/git/sflphone.git
git clone http://sflphone.org/git/sflphone.git
git clone git://git.debian.org/git/dpkg/dpkg.git dpkg
git clone http://git.debian.org/git/dpkg/dpkg.git dpkg

Affichage Web

try http://git.debian.org/?p=dpkg/dpkg.git;a=summary

Affichage Bureau

gitk

Checkout d'une branche = checkout

exemple:
git checkout<TAB><TAB> # autocompletion avec la liste des branches
man git-checkout # aide
# get the branche 1.10.1
git checkout 1.10.1
# get the external branche origin/sourcev3 and create a local one "sourcev3" with the -b option
git checkout -b sourcev3 origin/sourcev3

Initialisation d'un projet

cd project/ && git init && git add . && git commit -m "first commit"

Service GitHub

Avec nom d'usager et mot de passe

Mise à jour: git push origin master

Service Bitbucket

mkdir -p /path/to/your/project
cd /path/to/your/project
git init
git remote add origin https://USERNAME@bitbucket.org/TEAMNAME/PROJECT.git

echo "USERNAME" >> contributors.txt
git add contributors.txt
git commit -m 'Initial commit with contributors'
git push -u origin master

Déplacement et remote

Scénario: j'ai fait un git init dans un dossier projet/ mais je veux le fusionner avec dépôt externe. Hors la racine est dans le répertoire html/.

# déplacement vieux projet dans projet/html
mv projet html/
mkdir projet
mv html projet/

# déplacement ancien git
cd projet
mv html/.git .
git add html
git commit -a -m "rebase"

# adding and getting file from remote
git remote add origin https://progysm@bitbucket.org/hlteam/lecourant.git
git pull https://progysm@bitbucket.org/hlteam/lecourant.git HEAD

Piste: SO 1918111

git over http

    SetEnv GIT_PROJECT_ROOT /var/www/vhost/domain/git
    AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /var/www/vhost/domain/git/$1
    AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/vhost/domain/git/$1
    ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

    RewriteEngine On
    RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
    RewriteCond %{REQUEST_URI} /git-receive-pack$
    RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]

    <LocationMatch "^/git/">
        Order Deny,Allow
        Deny from env=AUTHREQUIRED

        AuthType Digest
        AuthName "Git"
        AuthDigestProvider file
        AuthUserFile /etc/apache2/auth/git-htdigest
        AuthDigestDomain / https:/domain/
        Require valid-user
        Satisfy Any 
    </LocationMatch>

Creating the repository on server

# server:
# see also https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

cd /var/www/vhost/domain/git/
mkdir projectname.git
cd projectname.git

git init --bare
touch git-daemon-export-ok

chmod g+ws .
chmod -R g+w .
chown -R user:www-data .

Pushing the code from the client to the server

# client:
cd directory/

git init
# checking config with git config -l
git add file
git commit -m "first commit"
git remote add origin https://domain/git/projectname.git
git push -u origin master