I would like to check out the latest state of a remote git branch in a script for some integration-tests.
The branch name can be changed by the programmer in between runs. I would like git not to fully clone the whole repository each time in order not to lose too much time.
Since the script gets run regularly on an existing repo, the branch can already exist locally.
I have a hard time getting the commands right. The solution below fails to pull when a remote (unrelated branch) is deleted.
if cd $builddir ;
then git fetch origin $gitbranch && git checkout --track $gitbranch ; git pull
else git clone --branch $gitbranch $gitrepo $builddir;
fi
Is there an elegant solution for this? I am using git 1.7.1 on Centos 6.5.