Home > Blockchain >  git pull and merge in automated build
git pull and merge in automated build

Time:03-08

I have an automation build script. Now, if there is any modified files in the git branch local, I stash it, then I do git checkout . But, based on the present branch, it may not be possible to pull the branch to be deployed as it asks for merge. So, the code part is like this:

if [[ "git status --porcelain --untracked-files=no" ]]; then
    d=$(date  %Y-%m-%d)
    commit_message="stash before release build date:${d}"
    git stash push -m "${commit_message}"
fi
git checkout ${branch}
retVal=$?
if [ $retVal -ne 0 ]; then
    exit 1
fi
git pull
<build code>

But the problem is, while running this script, it hangs. My most probable guess is, its unable to do automatic git pull after changing branches. Any inputs will be appreciated.

I really cannot think of scenario when default merge in git pull wouldn't be successful.

my scenario is this: I am in branch 'A'. I stashed any modified changes. I want to checkout branch 'B'. I will update from origin. Then the build script runs.

Thanks and Regards,
Sudip

CodePudding user response:

I really cannot think of scenario when default merge in git pull wouldn't be successful.

It could fail if the remote branch was rebased.

I understand you want to checkout (and then build) some branch as it is in a remote repository. In that case don't do a checkout and pull but rather a fetch and checkout:

  • git fetch origin A
  • git checkout origin/A (ignore the warning about the detached HEAD)

That way you can even build branches that don't exist in your local repo. And you do not run into problems if the branch was rebased and pushed to the remote and therefore does not merge into your local branch (remember: pull is basically just a shortcut for fetch and merge).

  •  Tags:  
  • git
  • Related