4. Git

There are many different version control systems in the world, but in the last year Git has become the most popular SCM. Although it may not be the best program it is hip and cool, so many development suites offer an integration with Git. This tutorial also focuses on Git, not because the author considers Git the best tool in town, but because it is accepted by most users, well documented, and has much support.

Git basically is a distributed SCM. That means that the repository including the whole history of changes can be saved to everywhere. People can clone from a repository to create a new one, push back from one repo to a different one is possible. In the software development users often use light-weight branches, a special feature of git. While this is a very useful method to isolate feature development and bug fixing as single tasks its benefit is limited in the use of 3D modelling. Of course, branching is useful for many use cases, but due to its complexity and the target audience of this web page it will not be explained here.

With Git and the surrounding development and lifecycle tools very complex workflows are possible, e.g. including review phases before changes will be introduced into the master branch. Also these workflows will not be explained here.

4.1 Installation

Git is open-source. It can be downloaded and installed on almost every operating system. After the installation there are the command line tools as well as (for Windows) two graphical user interfaces (GUI) to these tools. On Linux systems mostly the GUIs need to be installed independently from the pure command line software.

Nevertheless the author recommends to use either the command line tools or third party development tools with a binding to git in case the user prefers a GUI. In this tutorial we will purely use the command line.

4.2 Configuration

With every commit the information about the author shall be logged. Therefore git needs this information:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

4.3 Usage

There are many ways to use Git. In this tutorial we start working with a repository and a workspace, which both reside on the local computer. While this setup is far from being optimal, it already offers a lot of advantages. Later we will expand this setup to a storage in the cloud and with automatic builds.

4.4 Creating a repository with initial content

Everything typically starts with some sample files. Lets assume we have a directory c:\project in which we have a Blender file project.blend. Let's first turn this directory to be a repository. Change into that directory and use this command on the command line (Windows: click on the start menu icon and type cmd and return key to have a command line):

git init

As result the directory becomes a git repository. You can recognize this because the directory now contains a folder .git. The local work space and the repository are stored in c:\project.

Alternatively you could create a so-called "bare" repository without a work space. But for now let's ignore this option.

The files in the work space are still not added to the repository. We want to add the initial file to the repo and additionally want to convince git to ignore backup files that are stored with .blend1 as extension (because git will help us with backups). Therefore let's create a file .gitignore in c:\project with this content:

*.blend1
You can use a text editor for this. As next step let's commit the files to the repository:
git config --global alias.add-commit '!git add -A && git commit'
git add-commit * -m "Initial Commit"
This way the files are added with the comment "Initial Commit".

4.5 Change the files and commit

Let's add an image texture.png to the directory and change the Blender file in the way that an object is moved and has a texture with the added image.

Start adding the image file to the so-called index of git:

git add template.png

This way git knows that there is a new file that shall be added to the repository on the next commit.

So now let's commit the changes (object move and texture):

git commit -m "Object is moved and got a texture"

The change set consiting of texture.png and the modified project.blend is now committed to the repository with the comment "Object is moved and got a texture". If you want to see the last changes you can use

git log