我维护另一个项目的测试 git 存储库。在此存储库中,我们有映射到不同环境进行测试的分支:
Bitbucket 有一个很好的功能,任何要掌握的拉取请求也可以合并到开发分支中。我们经常利用此功能,因为我们添加的测试通常可以在所有环境中运行。问题是我们还有另外 2 个分支需要从 master 进行更改。
每当对 master 进行更改时,我都会运行一个 Jenkins 作业设置,该作业设置应该将这些 master 更改拉入其他分支,但我不断收到此错误:
error: failed to push some refs to 'my_repo'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这就是詹金斯工作的作用:
git fetch
git branch -D ci_env (branch that should also get master changes)
git checkout -b ci_env origin/ci_env
git pull origin master
git push
这些是 Jenkins 节点上的全局配置:
+ git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=****my_repo****
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
将其添加到您的管道中可能是您最好的选择。
# one time setup
git remote add ci_env <ci_env_repo_url>
# on master after changes are made
git push ci_env HEAD
这将添加
ci_env
的远程上游,当更改推送到 master 时,您可以将最新更改推送到远程 HEAD