假设我在远程存储库上有这个分支:
./master
./develop
./feature/A
./feature/B
我想 pull 特定分支,如果该分支不存在,我想默认为开发或掌握。 如果功能分支不存在,则开发是默认后备 如果开发不存在,master 是默认后备。
我工作的项目有很多存储库,但只有其中一些有功能分支。 其他存储库有主分支和集成分支,有些只有主分支。
我想编写一个脚本,该脚本将 pull 具有特定分支(feature/B)的所有存储库,如果当前存储库没有该分支,我想 pull 开发或掌握。
最佳答案
简单的 bash OR 对你有用吗?
git checkout foo || git checkout master
error: pathspec 'foo' did not match any file(s) known to git
Switched to branch 'master'
Your branch is behind 'origin/master' by 30 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
基本上,如果git checkout foo
成功 - 完成。如果失败,调用git checkout master
关于Git 尝试 checkout 分支或默认分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70436600/