Correct way of checkout and build from a branch

My team use a simple model with Git.

Master branch is the latest development and is considered as unstable.
For RC (ReleaseCandidate) we make a new branch for every release and use the version as branchname. Like “2018.09”.

So the buildscript checkout and build master every morning.
Then on demand it can also build the named RC.

The git part of buildscript look like this:

git clean -fd // Git generic action to remove generated files etc
git fetch // Git fetch action with tags and force option checked
git checkout -f %BranchName% // Git generic action to choose branch
git reset --hard origin/%BranchName% // Git generic action to reset index
git pull %Repository% // Git generic ation to pull repository
git rebase --skip // Git generic action that rebase

If the last rebase action is fails it is ignored.

Now the problem is that RC builds can get commits from master branch.
I also had a feeling that the this sequence of actions can be simplified.

It should just reset everything and get the latest from specified branch to working dir.
Any advice how to improve/fix this ?

I’m not a git expert, so it took me a few minutes with google to figure out why you are doing all those steps. I can’t really offer much that would help here, this might be a question for stackoverflow, more likely to get some expert git advice there.

That said, I would consider using a separate directory per branch for this, using a shallow clone per branch

or

This way you can skip all the cleaning and resetting etc.

The other (better imho) option is to use Continua CI - which does each build in a clean folder (efficiently) - it works well with FinalBuilder and handles branches etc easily.

See this Blog Post for more information about using FinalBuilder and Continua CI together.

The process we use in Continua CI can be simplified as follows:

git fetch //get latest changes from remote repo
git checkout --force %BranchName% //update working folder with files at branch head
git status --porcelain //check for deleted files in working folder - can happen if files have been renamed
git checkout --force %BranchName% //run checkout again to update missing files (only if git status command reported delete files
git clean --force -d //remove any untracked files from working folder

We run several other commands to list changes, and deal with submodules, tags and post checkout scripts, but this should be all that you need to get a clean list of files in a working folder.

Note that we don’t make any changes to the working folder that we want to keep or commit so we don’t need to use the git pull, git rebase or git reset commands.

1 Like

I got help now.

This seems to work

git fetch
git checkout -f %BranchName%
git reset --hard HEAD
git pull

Another option is this

Clear all files in git folder
git clone --depth 1 --single-branch --branch %branchname% git@github.com:Attracs/%RepoName%.git %STAGE_ROOT%%RepoName%

That is surprisingly fast. as it not download the history and only one branch

In case someone else have similar problems