Difference between revisions of "Git"

From WhyAskWhy.org Wiki
Jump to: navigation, search
m (Rearranged content and added more links)
m (Added questions regarding creating and sharing a repo vis HTTP(s))
Line 49: Line 49:
 
</pre>
 
</pre>
  
 +
 +
=== How do you create a Git repository and prep it for sharing via HTTP? ===
 +
 +
<syntaxhighlight lang="bash">
 +
mkdir /var/www/git/repos/project.git
 +
cd /var/www/git/repos/project.git
 +
git --bare init
 +
chown -R www-data:www-data /var/www/git/repos/project.git
 +
sudo -u www-data git update-server-info
 +
cd /var/www/git/repos/project.git
 +
mv hooks/post-update.sample hooks/post-update
 +
</syntaxhighlight>
 +
 +
 +
=== What if you wanted that Git repository to be a clone of another repository? ===
 +
 +
<syntaxhighlight lang="bash">
 +
git clone --mirror <remote repository>
 +
</syntaxhighlight>
 +
 +
or
 +
 +
<syntaxhighlight lang="bash">
 +
git clone --mirror /work/repo
 +
</syntaxhighlight>
 +
 +
 +
=== How do you share a Git repository via HTTP? ===
 +
 +
Several different web servers could be used for this, but here is an example using Apache 2.2.x. I've tried to make it pretty bare so it could apply the widest possible setups. For my setup I use a local LDAP server (same box as web server) instead of a password file. I feel this helps with user account/password management.
 +
 +
Note: For the SSL portion, the SSLCipherSuite directive may need a closer look as I have had that value in a conf file for several years and there may be a better approach to use.
 +
 +
<syntaxhighlight lang="apache">
 +
##################################################################
 +
# vhost settings for git.example.org
 +
##################################################################
 +
 +
<VirtualHost *:8080>
 +
    DirectoryIndex index.html
 +
    UseCanonicalName off
 +
 +
    ServerName git.example.org
 +
    ServerAdmin webmaster@example.org
 +
 +
    DocumentRoot /var/www/example.org/git
 +
 +
    # Enable SSL for this vhost
 +
    SSLEngine on
 +
 +
    # Path to certificate and key
 +
    SSLCertificateFile  /etc/ssl/mycerts/wildcard.example.org_server.crt
 +
 +
    # Should be kept where only root can get to it.
 +
    SSLCertificateKeyFile /etc/ssl/private/wildcard.example.org_server.key
 +
 +
    # allow all ciphers for the initial handshake,
 +
    # so export browsers can upgrade via SGC facility ...
 +
    SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
 +
 +
    <Location />
 +
        SSLOptions +StrictRequire
 +
 +
        # REQUIRE SSL for all connections
 +
        # http://httpd.apache.org/docs/2.1/mod/mod_ssl.html#sslrequiressl
 +
        SSLRequireSSL
 +
 +
        # ... but finally deny all browsers which haven't upgraded
 +
        SSLRequire %{SSL_CIPHER_USEKEYSIZE} >= 128
 +
    </Location>
 +
 +
#########################################################
 +
# misc git repos
 +
#########################################################
 +
 +
    Alias /repos /var/www/git/repos
 +
    <Location /repos>
 +
        DAV on
 +
        Options ExecCGI FollowSymLinks Indexes
 +
 +
        #####################################
 +
        # Apache auth options
 +
        #####################################
 +
 +
        Satisfy All
 +
        AuthUserFile /usr/local/apache/access/git-repos.htpasswd
 +
        Require valid-user
 +
 +
    </Location>
 +
 +
    # The goal is to apply the CGI options to any git repo's hooks dir
 +
    # under /var/www/git/repos
 +
    <DirectoryMatch "^/var/www/git/repos/.+/hooks/.+">
 +
        SetHandler cgi-script
 +
        Options +ExecCGI
 +
    </DirectoryMatch>
 +
</VirtualHost>
 +
</syntaxhighlight>
  
  
Line 58: Line 156:
 
</references>
 
</references>
  
=== git fetch - Manual Page ===
+
=== Manual Pages ===
 +
 
 +
==== git fetch ====
  
 
* [http://git-scm.com/docs/git-fetch git-scm.com]
 
* [http://git-scm.com/docs/git-fetch git-scm.com]
 
* [http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html kernel.org]
 
* [http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html kernel.org]
 +
 +
 +
=== Sharing a Git repository via HTTP(s) ===
 +
 +
* [http://davidmnoriega.tumblr.com/post/8182385119/setting-up-git-on-apache-ssl-ldap Field Notes of a SysAdmin: Setting up Git on Apache+SSL+LDAP]
 +
* [http://joemaller.com/990/a-web-focused-git-workflow/ A web-focused Git workflow]
 +
* [http://pragprog.com/book/pg_git/pragmatic-guide-to-git Pragmatic Guide to Git]
 +
* [http://shop.oreilly.com/product/0636920022862.do Version Control with Git]
  
  

Revision as of 13:36, 1 September 2012


My scratch notes on Git. Someday this page may actually be useful.

Questions

By answering these questions, I'll have a "cheat sheet" of useful tips/tricks to consult in the future.

How can you tell what branch or tag your working copy is on?

What if you are not seeing a tag that you know is available?

For example I had a copy of the MediaWiki 1.19.1 tag checked out [1] and even though a 1.19.2 tag was available I didn't see it when running git tag -l.

Running git fetch [2] seemed to do the trick:

remote: Counting objects: 96, done
remote: Finding sources: 100% (49/49)
remote: Getting sizes: 100% (58/58)
remote: Compressing objects: 100% (11/11)
remote: Total 49 (delta 30), reused 36 (delta 28)
Unpacking objects: 100% (49/49), done.
From https://gerrit.wikimedia.org/r/p/mediawiki/core
   49857f8..f25ee70  REL1_19    -> origin/REL1_19
   566852d..944e196  master     -> origin/master
 * [new tag]         1.19.2     -> 1.19.2


How do you switch from one tag to another?

Using our earlier example, let's switch from the 1.19.1 tag to the 1.19.2 tag.

git checkout 1.19.2

Previous HEAD position was d0c0aab... Merge "Bump $wgVersion and add release-notes for 1.19.1" into REL1_19
HEAD is now at f25ee70... Release notes and increment version


How do you create a Git repository and prep it for sharing via HTTP?

mkdir /var/www/git/repos/project.git
cd /var/www/git/repos/project.git
git --bare init
chown -R www-data:www-data /var/www/git/repos/project.git
sudo -u www-data git update-server-info
cd /var/www/git/repos/project.git
mv hooks/post-update.sample hooks/post-update


What if you wanted that Git repository to be a clone of another repository?

git clone --mirror <remote repository>

or

git clone --mirror /work/repo


How do you share a Git repository via HTTP?

Several different web servers could be used for this, but here is an example using Apache 2.2.x. I've tried to make it pretty bare so it could apply the widest possible setups. For my setup I use a local LDAP server (same box as web server) instead of a password file. I feel this helps with user account/password management.

Note: For the SSL portion, the SSLCipherSuite directive may need a closer look as I have had that value in a conf file for several years and there may be a better approach to use.

##################################################################
# vhost settings for git.example.org
##################################################################

<VirtualHost *:8080>
    DirectoryIndex index.html
    UseCanonicalName off

    ServerName git.example.org
    ServerAdmin webmaster@example.org

    DocumentRoot /var/www/example.org/git

    # Enable SSL for this vhost
    SSLEngine on

    # Path to certificate and key
    SSLCertificateFile   /etc/ssl/mycerts/wildcard.example.org_server.crt

    # Should be kept where only root can get to it.
    SSLCertificateKeyFile /etc/ssl/private/wildcard.example.org_server.key

    # allow all ciphers for the initial handshake,
    # so export browsers can upgrade via SGC facility ...
    SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

    <Location />
         SSLOptions +StrictRequire

         # REQUIRE SSL for all connections
         # http://httpd.apache.org/docs/2.1/mod/mod_ssl.html#sslrequiressl
         SSLRequireSSL

         # ... but finally deny all browsers which haven't upgraded
         SSLRequire %{SSL_CIPHER_USEKEYSIZE} >= 128
    </Location>

#########################################################
# misc git repos
#########################################################

    Alias /repos /var/www/git/repos
    <Location /repos>
        DAV on
        Options ExecCGI FollowSymLinks Indexes

        #####################################
        # Apache auth options
        #####################################

        Satisfy All
        AuthUserFile /usr/local/apache/access/git-repos.htpasswd
        Require valid-user

    </Location>

    # The goal is to apply the CGI options to any git repo's hooks dir
    # under /var/www/git/repos
    <DirectoryMatch "^/var/www/git/repos/.+/hooks/.+">
        SetHandler cgi-script
        Options +ExecCGI
    </DirectoryMatch>
</VirtualHost>


References

  1. I'm used to SVN, so this may be the wrong terminology
  2. What's the difference between fetch and pull?

Manual Pages

git fetch


Sharing a Git repository via HTTP(s)


Unsorted links

These are just Git related links that I've dumped from my bookmarks folder. I'll go back and prune duplicates.