Git

From IdefixWiki
Jump to: navigation, search

Contents

GIT

Configure git:

git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global core.autocrlf false
git config --global core.savecrlf false 

Checkout the first version with git:

git clone idefix.fechner.net:masterthesis.git masterthesis

Have several copies on several places and sync it with the master server (like svn):

mkdir repo
cd repo
git init repo
git pull ssh://user@server/dir/
git remote add origin git@server:pluginname.git
git config branch.master.remote 'origin'
git config branch.master.merge 'refs/heads/master'
git push origin master:refs/heads/master

GIT and SVN

Checkout a SVN Repo

At first we have to create a translation file for the authors:

svnuser1 = First User <user@hellospambot.com>
svnuser2 = Another User <anotheruser@whatever.com>

To get a list of users you can execute the following small shell script:

#!/bin/sh
#
# Extract information from /etc/passwd and build up a translation file for git.
# It extracts the infos to a file called authors-PID.txt
#
# (c) 2010 Matthias Fechner
#
TMPFILE=/tmp/tmp-authors-$$.tmp
EXPORTFILE=authors-$$.txt
svn -q log | grep '^r' | cut -d ' ' -f 3 | sort | uniq > $TMPFILE
rm $EXPORTFILE
for i in `cat $TMPFILE`
do
echo "Search user $i"
echo -n "$i = " >> $EXPORTFILE
USERSTRING=`grep '^'$i':' /etc/passwd | cut -d ':' -f 5`
echo "  found $USERSTRING"
FULLNAME=`echo $USERSTRING | cut -d ',' -f 1`
echo "  found $FULLNAME"
echo -n $FULLNAME >> $EXPORTFILE
EMAIL=`echo $USERSTRING | cut -d ',' -f 5`
echo " <$EMAIL>" >> $EXPORTFILE
done
rm $TMPFILE

To get only a list of all people commited into the repository:

svn -q log | grep ^r | cut -d '|' -f 2 | sort | uniq

Then we can do a clone:

git svn clone <svn repo url> -A authors.txt -s <destination dir name>

Working on it

With git-svn, you get by default a local branch named master. You should not do any work on it, only keep it up-to-date with the svn trunk branch.

git checkout master
git svn fetch
git svn rebase

If you want to do some modifications create a local branch:

git branch local-devel
git checkout local-devel

Now change the code, test it and do local commits:

fix the bug, compile, test,
git commit -a
fix the bug, compile, test,
git commit -a

If you ready and want to commit it to the remote repository we have to update our local trunk and rebase (do not use git merge, it will through away your commit messages) it:

git checkout master
git svn fetch
git svn rebase
git rebase --interactive --preserve-merges local-devel
git svn dcommit

Now we can remove our local branches:

git branch -D local-devel

Convert subversion to git with not all branches and tags

Init the new repository:

mkdir newdir
cd newdir
git svn init svn://server/path -s
git config svn.authorsfile ~/authors

Now edit .git/config

[svn-remote "svn"]
    url = svn://server
    fetch = server/trunk:refs/remotes/trunk
    branches = server/branches/{branch1, branch2}:refs/remotes/branches/*

Then clone it with:

git svn fetch

Ignore all files which are ignored by subversion:

git svn show-ignore > .gitignore

Convert all remote branches and tags to local ones by using the script [1]:

svn2git --no-clone

Cleanup:

git gc --aggressive
git fsck --unreachable

Using GIT as Central Repository on a Server

To use a git repository on a central server to sync it between several computers we will convert it to a bare repository and place the bare repository on a place we like to share it. For this the first step is to create this bare repository with:

umask 007
cd /usr/local/gitroot
git clone --bare /tmp/repo-to-clone.git my-shared-repo.git

Finally we have to set some parameters to share it:

cd my-share-repo.git
git config core.sharedRepository 1
git config receive.denyNonFastForwards true
find objects -type d -exec chmod 02770 {} \;

Check 'git help config' to see what the parameters will do. If you create a new repository you can use also 'git init --shared my-share-repo.git'.

Now can can clone the repository change files commit it and push it to the server.

Convert SVN to GIT

First step is to create a translation file for the users. Follow here Checkout a SVN Repo to create this author file.

GitoLite

Install gitolite

Gittolite is a nice tool to manage access and git repositories with an additional admin-repository.

Server Site

Install the port by:

cd /usr/ports/devel/gitolite/
make install
make clean

Now we create the home dir of the git user:

mkdir /usr/local/git
chown git:git /usr/local/git

Set a password for the user git:

passwd git

Client Site

Now we copy our public key to the server with:

scp ~/.ssh/id_rsa.pub git@server:name.key

Now login with the user git and ssh:

ssh git@server

Now we setup the gitolite repo:

gl-setup name.key
exit vi without modification on the file.
exit

Checkout the admin repository with:

git clone git@server:gitolite-admin

Do your modification, commit it and push it back to the server.

Move existing repo to gitolite

At first we create a new repo using the gitolite mechanism by editing the file gitolite.conf from the cloned gitolite-admin repository:

repo newrepo
  RW+ = user

Commit this change and push it to the server.

Now we can push our existing repo into gitolite. Go to the repo you want to push into your gitolite managed repos and insert:

git push --all git@server:newrepo
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox