Product SiteDocumentation Site

1.2.4. Checking out branches

By default, the new clone will only track code from the primary remote branch, master, which is the latest development version of MantisBT. If you are planning to work with stable release or other development branches, you will need to set up local tracking branches in your repository.
The following command will set up a tracking branch for the current stable branch, master-1.3.x.
git checkout -b master-1.3.x origin/master-1.3.x


With the introduction of submodules for some of the third-party libraries, you may encounter issues when switching to an older branch which still has code from those libraries in a subdirectory of /library rather than a submodule:
$ git checkout old_branch
error: The following untracked working tree files would be overwritten by checkout
	(list of files)
To resolve this, you first have to get rid of the submodules directories before you can checkout the branch. The command below will move all submodules to /tmp:
sed -rn "s/^.*path\s*=\s*(.*)$/\1/p" .gitmodules |xargs -I{} mv -v {} /tmp
git checkout old_branch
Alernatively, if you don't care about keeping the changes in the submodules directories, you can simply execute
git checkout -f old_branch
git clean -df
When switching back from the older branch, the submodules directories will be empty. At that point you can either
  • Update the submodules to reclone them
    git submodule update
  • Restore the directories previously moved to /tmp back into the empty directories, e.g.
    sed -rn "s/^.*path\s*=\s*(.*)$/\1/p" .gitmodules |xargs -n 1 basename |xargs -I{} mv -v /tmp/{} library
For further reference: Pro Git book