Revisioncontrol with Git

The most fundamental difference between Git and other revision control systems like SVN or CVS is the way how you work with it. With Git you will usually clone a repository. This creates a directory on your desktop where all the data about all revisions is stored. This means that you are not depending on a server somewhere. You can easily just use git locally.

Local install

Most current linux distributions include a package git-core and maybe also git-gui If you are using Windows you should have a look at msysgit

After the initial install you should configure the your user information:

git config --global username mail@domain.ch

Install on a server for example QNAP NAS TS-209

You can just install git the same way as with the local install. On a TS-209 this means:

ipkg update
ipkg install git-core

You can create a repository on the server as follows:

mkdir repositorydir.git
cd repositorydir.git
git --bare init

with --bare your files will just be saved in the binary git-format.

To use that repository on the local machine you will need to create an empty repository and the you can specify the remote one as a remote destination. The command push allows you to writer local changes onto the server and fetch allows you to read updates from the server and apply them locally.

mkdir repository
cd repository
git init
git remote add origin user@SERVER:/pathtorepositorydir/repositorydir.git
git push origin master

Full syntax for SSH-Url:

ssh://user@SERVER:PORT/pathtorepositorydir/repositorydir.git

or

ssh://user:password@SERVER:/pathtorepositorydir/repositorydir.git

Caution: you cannot define the password for the user (not user:password@SERVER:PORT) if you define a port!

Using git for a SVN-Repository

Usually you just need to install the package git-svn. After that you can use a SVN repository just the same way as you would use a git repository. You just need to type git-svn instead of git for all commands.

Import an SVN repository:

git svn clone SVNURL LOCALNAME

Fetch updates

git-svn rebase

Ignore filemode changes

Just execute the following command:

git config core.filemode false

Problems with git

  • Trailing Whitespace Error
    This pre-commit Error can be fixed easily. Just remove the following lines from the file .git/templates/hooks/pre-commit:
    if (/\s$/) {
    	bad_line("trailing whitespace", $_);
    }
    
  • git-receive-pack: command not found
    sh: git-receive-pack: command not found
    fatal: The remote end hung up unexpectedly
    

    The reason for that error is the PATH variable which will not be set if you are using a not-interactive SSH connection. For an easy fix you could just make links to the necessary binaries in you /bin folder:

    cd /bin
    ln -s /opt/bin/git-receive-pack
    ln -s /opt/bin/git-upload-pack
    ln -s /opt/bin/git 
    

Sources

Tags:

Add new comment