Part 1: Install and learn git on OSX

  1. Install Git For OSX.

  2. Introduce yourself to Git.

rupert:~ rupert$ git config --global user.name "John Doe"
rupert:~ rupert$ git config --global user.name "john@gmail.com"
  1. Some git settings I learned from http://dysinger.net/2007/12/30/installing-git-on-mac-os-x-105-leopard/
rupert:~ rupert$ git config --global color.diff auto
rupert:~ rupert$ git config --global color.status auto
rupert:~ rupert$ git config --global color.branch auto
rupert:~ rupert$ git config --global color.interactive auto
 
rupert:~ rupert$ git config --global alias.st status
rupert:~ rupert$ git config --global alias.ci commit
rupert:~ rupert$ git config --global alias.co checkout
rupert:~ rupert$ git config --global alias.br branch
 
rupert:~ rupert$ git config --global core.excludefile ~/.gitignore
rupert:~ rupert$ echo ".DS_Store" >> ~/.gitignore

More tips

  1. Familiarizing with git commands:
  • http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
  • http://www.kernel.org/pub/software/scm/git/docs/v1.2.6/core-tutorial.html
    rupert:projects rupert$ mkdir sample_git_project
    rupert:projects rupert$ cd sample_git_project/
    rupert:sample_git_project rupert$ git init
    Initialized empty Git repository in /Users/rupert/projects/sample_git_project/.git/
    <pre>
     
    5. Like .svn there is also .git
    <pre lang="bash">
    rupert:sample_git_project rupert$ ls -la
    total 
    drwxr-xr-x   3 rupert  staff  102 26 Aug 21:49 .
    drwxr-xr-x  10 rupert  staff  340 26 Aug 21:49 ..
    drwxr-xr-x  10 rupert  staff  340 26 Aug 21:49 .git
    1. Add files: file1, file2 to git repository.
    rupert:sample_git_project rupert$ pwd
    /Users/rupert/projects/sample_git_project
     
    rupert:sample_git_project rupert$ touch file2
    rupert:sample_git_project rupert$ echo "foo" >> file2
    rupert:sample_git_project rupert$ cat file2
    foo
    rupert:sample_git_project rupert$ git add file2
    1. Now, check which files need to be added in the repository by doing git status.
    rupert:sample_git_project rupert$ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       new file:   file2
    #
    1. Committing the newly added file. Enter your message then :wq!
    rupert:sample_git_project rupert$ git commit file2
      1 first draft of file2
      2 # Please enter the commit message for your changes. Lines starting
      3 # with '#' will be ignored, and an empty message aborts the commit.
      4 # Explicit paths specified without -i nor -o; assuming --only paths...
      5 #
      6 # Committer: rndguzmanjr@gmail.com <rupert@rupert.(none)>
      7 #
      8 # On branch master
      9 # Changes to be committed:
     10 #   (use "git reset HEAD <file>..." to unstage)
     11 #
     12 # new file:   file2
     13 #
    1. Now lets change file1 and use commit -a to automatically notice any modified files but not new ones. Notice on line 11 that we modified file1.
    rupert:sample_git_project rupert$ touch file3
    rupert:sample_git_project rupert$ echo "foo" >> file3
    rupert:sample_git_project rupert$ echo "bar" >> file1
    rupert:sample_git_project rupert$ cat file1
    foo
    bar
    rupert:sample_git_project rupert$ git commit -a
    1 added bar
      2 # Please enter the commit message for your changes. Lines starting
      3 # with '#' will be ignored, and an empty message aborts the commit.
      4 #
      5 # Committer: rndguzmanjr@gmail.com <rupert@rupert.(none)>
      6 #
      7 # On branch master
      8 # Changes to be committed:
      9 #   (use "git reset HEAD <file>..." to unstage)
     10 #
     11 # modified:   file1
     12 #
     13 # Untracked files:
     14 #   (use "git add <file>..." to include in what will be committed)
     15 #
     16 # file3
    1. Git tracks content not files. Below is the result after :wq! on step 9.
    rupert:sample_git_project rupert$ git commit -a
    [master abc91dd] added bar
     1 files changed, 1 insertions(+),  deletions(-)
    1. Tracking changes..
    git log
    git log -p
    git log --stat --summary
    rupert:sample_git_project rupert$ git log
    commit abc91dd859117ad0bcaa379b0496681f2a2def7b
    Author: rndguzmanjr@gmail.com <rupert@rupert.(none)>
    Date:   Wed Aug 26 22:06:42 2009 +1000
     
    added bar
     
    commit 7cf76a9fdee86a26e4abb2e32a1356ad6b0cbb06
    Author: rndguzmanjr@gmail.com <rupert@rupert.(none)>
    Date:   Wed Aug 26 21:55:21 2009 +1000
     
    first draft of file2
     
    commit a2a66b30fe90e2ef315375434a3b9a17a4ed8b68
    Author: rndguzmanjr@gmail.com <rupert@rupert.(none)>
    Date:   Wed Aug 26 21:53:49 2009 +1000
     
    sample commit

    Part 2: Creating an initial remote repository and making it available using HTTP WebDav.
    Now, for our tutorial, I’ve setup a virtual host of git.gisnotes.com in a Linode. We will setup webdav on Apache, create our initial git repository and test if from the client.

    In my remote linode debian…

    1. Install WebDav on your apache2
    $:/etc/apache2/mods-available
    $ sudo a2enmod dav_fs
    1. Add a repository configuration in apache2 for webdav.
    <VirtualHost git.gisnotes.com:80>
        ServerAdmin rndguzmanjr@gmail.com
        ServerName gisnotes.com
        ServerAlias git.gisnotes.com
        DocumentRoot /data/www/git.gisnotes.com/
        CustomLog /var/www/log/git.gisnotes.com/access.log combined
        ErrorLog /var/www/log/git.gisnotes.com/error.log
     
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
     
        <Location /repos/repo.git>
               DAV on
               AuthType Basic
               AuthName "Git"
               AuthUserFile /etc/apache2/passwd.git
               Require valid-user
        </Location>
     
    </VirtualHost>
    1. Create the password file.
    htpasswd -c /etc/apache2/passwd.git <user>
    1. Create the initial git repository.
    $ sudo mkdir repo.git
    $ cd repo.git/
    $ sudo git --bare init
    Initialized empty Git repository in /var/cache/git/repo.git/
     
    $ sudo chown -R www-data.www-data .
     
    $ sudo git update-server-info
    1. Check from the browser if the user/password works.

    http://git.gisnotes.com/repos/repo.git

    username:
    password:

    If you can see the contents of the repo, then you’re all good.

    Still having problems?

    http://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt

    Part 3: Making changes locally then pushing it remotely.
    In my MacOSX client…

    1. Add the following to your ~/.netrc so it won’t asked for the password all the time.
    vim ~/.netrc
    machine git.gisnotes.com
    login rupert
    password ******
     
    chmod 600 ~/.netrc
    1. Check if netrc works:
    curl --netrc --location -v http://rupert@git.gisnotes.com/repos/repo.git/HEAD
    1. Now let’s do an initial checkout of the repository in our local machine.
    $ git clone "http://git.gisnotes.com/repos/repo.git" repo
    Initialized empty Git repository in /Users/rupert/projects/test/repo/.git/
    warning: You appear to have cloned an empty repository.
    1. Now this is important. If you don’t do this then you cannot push your changes remotely. Go inside the repo directory then tell git where the remote upload url of our remote git repository.
    $ cd repo
    $ git config remote.upload.url \ http://rupert@git.gisnotes.com/repos/repo.git/
     
    $ git config -l
    user.name=foo@gmail.com
    color.diff=auto
    color.status=auto
    color.branch=auto
    color.interactive=auto
    alias.st=status
    alias.ci=commit
    alias.co=checkout
    alias.br=branch
    core.excludefile=/Users/rupert/.gitignore
    core.repositoryformatversion=
    core.filemode=true
    core.bare=false
    core.logallrefupdates=true
    core.ignorecase=true
    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
    remote.origin.url=http://git.gisnotes.com/repos/repo.git
    branch.master.remote=origin
    branch.master.merge=refs/heads/master
    remote.upload.url= http://rupert@git.gisnotes.com/repos/repo.git/
    1. Lets make a project inside repo/.
    $ pwd
    /Users/rupert/projects/test/repo
     
    $ mkdir mytestproject
    $ cd mytestproject
    $ touch file1
    $ echo "foo bar" >> file1
    $ git add mytestproject

    Just like in Part 1, we can see from git status that we have a new file..

    $ git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    #   (use "git rm --cached <file>..." to unstage)
    #
    #       new file:   mytestproject/file1
    #

    We now commit the changes locally. Note, this is not yet commited remotely..

    $git commit -a . 
      1 first draft of file1
      2 # Please enter the commit message for your changes. Lines starting
      3 # with '#' will be ignored, and an empty message aborts the commit.
      4 #
      5 # Committer: rndguzmanjr@gmail.com <rupert@rupert.(none)>
      6 #
      7 # On branch master
      8 #
      9 # Initial commit
     10 #
     11 # Changes to be committed:
     12 #   (use "git rm --cached <file>..." to unstage)
     13 #
     14 # new file:   mytestproject/file1
     15 #
     
    $ git commit -a
    [master (root-commit) 66579da] first draft of file1
     1 files changed, 1 insertions(+),  deletions(-)
     create mode 100644 mytestproject/file1
    1. Now we commit it remotely..
    $ git push origin master
    Fetching remote heads...
      refs/
      refs/heads/
      refs/tags/
    updating 'refs/heads/master'
      from 0000000000000000000000000000000000000000
      to   66579dae65d13c3c521a64f8007246e72c53c16b
    sending 4 objects
    done
    Updating remote server info
    PUT error: curl result=22, HTTP code=403

    Part 4. How do we know if its committed remotely? Lets use gitweb.

    1. Install gitweb
    $~$ sudo apt-get install gitweb
    [sudo] password for rupert: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Suggested packages:
      git-doc
    The following NEW packages will be installed:
      gitweb
     upgraded, 1 newly installed,  to remove and 15 not upgraded.
    Need to get 268kB of archives.
    After this operation, 512kB of additional disk space will be used.
    Get:1 http://security.debian.org stable/updates/main gitweb 1:1.5.6.5-3+lenny2 [268kB]
    Fetched 268kB in 0s (2448kB/s)
    Selecting previously deselected package gitweb.
    (Reading database ... 30959 files and directories currently installed.)
    Unpacking gitweb (from .../gitweb_1%3a1.5.6.5-3+lenny2_all.deb) ...
    Setting up gitweb (1:1.5.6.5-3+lenny2) ...
    1. Navigate thru your gitweb.cgi and see the changes.

    http://servername/cgi-bin/gitweb.cgi

    1. Undo last git commit that have not yet been pushed
    git reset --soft HEAD~1