New to Git?
See here: Git
or here: Pro Git Book (CC ND SA 3.0) by Scott Chacon and Ben Straub
The clone operation creates a local repository by copying information from a source repository. In the standard behavior, git will bring the entire changes history from source repository to local repository. That means both source and local repository will have the same history at the clone moment.
Cloning Tiki
The basics
The basic and short syntax is git clone <repository> <directory>
, where the mandatory argument <repository>
is the source repository path or URL and the optional argument <directory>
is the directory name where git will create the local repository.
By default, the clone process creates a repository in a folder with the same name of source repository, so in this case, the folder for local repository will have the name tiki.
git clone https://gitlab.com/tikiwiki/tiki.git
By passing a second argument to clone command, it is possible to define the name to the folder for the cloned repository, like the examples below.
git clone https://gitlab.com/tikiwiki/tiki.git tiki
git clone https://gitlab.com/tikiwiki/tiki.git tikiwiki
git clone https://gitlab.com/tikiwiki/tiki.git .
Choosing a branch
By default, the clone operation creates a local repository having the current branch set to master. There is an option called --branch
to change this behavior. The examples below creates 4 clones, each one with a different branch set.
git clone --branch=21.x https://gitlab.com/tikiwiki/tiki.git tiki21
git clone --branch=18.x https://gitlab.com/tikiwiki/tiki.git tiki18
git clone --branch=15.x https://gitlab.com/tikiwiki/tiki.git tiki15
Please note that the examples above clone Tiki source repository with the entire history.
Dealing with Tiki huge repository
After a decade of contributions, Tiki history sizes 3GB when decompressed locally. That is too big when several Tiki instances is needed. As of now, two approaches were tested to deal with this problem:
- Share git objects with other clones
-
git clone --shared --reference=<local-repository> <repository> [<directory>]
-
- Trim history size
-
git clone --depth=1 <repository>
-
For example to create a clone of branch 24 in a folder named tiki24 without all the history, which is also called a shallow clone
git clone --depth=1 --branch=24.x https://gitlab.com/tikiwiki/tiki.git tiki24
More examples:
git clone --depth=1 --branch=21.x https://gitlab.com/tikiwiki/tiki.git tiki21
git clone --depth=1 --branch=21.x https://gitlab.com/tikiwiki/tiki.git .
Use master (previously called trunk):
git clone --depth=1 --branch=master https://gitlab.com/tikiwiki/tiki.git .
Sharing git history
That is a good approach to developers needing to have the full Tiki history, but without waste network bandwidth or disk space. Git is capable to borrow information from other local clone when creating a new clone. This reduces the network usage while cloning and reduces disk usage to maintain several Tiki instances.
Information sharing is set by using the option --reference=<local-repository>
and the option --shared
, where <local-repository>
is another clone made before.
The first step is to create a standard Tiki clone, like the example below.
git clone https://gitlab.com/tikiwiki/tiki.git tikiwiki
Then, other clones can be created by borrowing the information from the clone above.
git clone --branch=master --reference=./tikiwiki --shared https://gitlab.com/tikiwiki/tiki.git tikimaster
git clone --branch=21.x --reference=./tikiwiki --shared https://gitlab.com/tikiwiki/tiki.git tiki21
git clone --branch=18.x --reference=./tikiwiki --shared https://gitlab.com/tikiwiki/tiki.git tiki18
git clone --branch=15.x --reference=./tikiwiki --shared https://gitlab.com/tikiwiki/tiki.git tiki15
Trimming git history
Another available to reduce disk and network usage is the --depth=<n>
, where <n>
is the number of history entries desired to bring. This approach may not be so good to Tiki development, because the change history is not available. But it is good to keep track of file state when installing Tiki in a server.
git clone --branch=18.x --depth=1 https://gitlab.com/tikiwiki/tiki.git tiki18
git clone --branch=18.x --depth=2 https://gitlab.com/tikiwiki/tiki.git tiki18
On the examples above, just the last <n>
commits of branch 18.x will be available on local repository. All other information about branches and tags will not exist on local repository.
It is possible to have a cloned repository with the last <n>
commits of each branch available. This is done by passing --no-single-branch
to clone command.
Creating a workspace
This is just a suggestion on how to setup a workspace in a development environment. The paths below can be set up in Nginx, Apache or any other webserver.
mkdir "/var/www/html" cd "/var/www/html"
git clone https://gitlab.com/tikiwiki/tiki.git tiki
git clone --branch=20.x --shared --reference=./tiki https://gitlab.com/tikiwiki/tiki.git doc.tiki.org git clone --branch=20.x --shared --reference=./tiki https://gitlab.com/tikiwiki/tiki.git dev.tiki.org git clone --branch=18.x --shared --reference=./tiki https://gitlab.com/tikiwiki/tiki.git example.com git clone --branch=master --shared --reference=./tiki https://gitlab.com/tikiwiki/tiki.git tikimaster.docker git clone --branch=20.x --shared --reference=./tiki https://gitlab.com/tikiwiki/tiki.git tiki20.docker git clone --branch=19.x --shared --reference=./tiki https://gitlab.com/tikiwiki/tiki.git tiki19.docker git clone --branch=18.x --shared --reference=./tiki https://gitlab.com/tikiwiki/tiki.git tiki18.docker
After above commands, the working space should have this structure:
/var/www/html/tiki /var/www/html/doc.tiki.org /var/www/html/dev.tiki.org /var/www/html/example.com /var/www/html/tikimaster.docker /var/www/html/tiki20.docker /var/www/html/tiki19.docker /var/www/html/tiki18.docker
Reference