英文:
How can I update all branches when main/master has a push?
问题
我尝试了一些方法。这是我现在正在使用的内容。
```yaml
name: 更新分支
on:
push:
branches:
- main
jobs:
更新分支:
runs-on: ubuntu-latest
steps:
- name: 检出仓库
uses: actions/checkout@v2
- name: 获取分支名称
id: 分支
run: |
git ls-remote --heads origin | awk -F'/' '{print $3}' | grep -vE 'main$' > ${{ github.workspace }}/branches.txt
- name: 更新分支
run: |
while read -r branch; do
git checkout $branch
git merge origin/main --no-edit
git push origin $branch
done < ${{ github.workspace }}/branches.txt
如果我使用这个出现错误:
error: 路径规范 'reddit-fix' 未匹配到任何已知于 git 的文件
Error: 进程以退出代码 1 完成。
reddit-fix
是存在的分支。
我想知道是否有任何方法可以实现这一目标。我尝试过使用GitHub Marketplace上找到的一个操作 这个,但我无法使其工作。
<details>
<summary>英文:</summary>
I've tried a few things. This is what I'm using right now.
```yaml
name: Update Branches
on:
push:
branches:
- main
jobs:
update-branches:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get branch names
id: branches
run: |
git ls-remote --heads origin | awk -F'/' '{print $3}' | grep -vE 'main$' > ${{ github.workspace }}/branches.txt
- name: Update branches
run: |
while read -r branch; do
git checkout $branch
git merge origin/main --no-edit
git push origin $branch
done < ${{ github.workspace }}/branches.txt
I am getting an error if I use this:
error: pathspec 'reddit-fix' did not match any file(s) known to git
Error: Process completed with exit code 1.
reddit-fix
is a branch that exists.
I'd like to know if there is any way to achieve this. I've tried using an action I found on the GitHub marketplace this one, but I couldn't make this work.
答案1
得分: 0
Azeem 回答了这个问题。我将其发布为答案,以便我可以将问题标记为已解决。
使用 actions/checkout@v3,使用 fetch-depth: 0 获取所有分支。
还要添加 git config --global user.email "
这里 是一个包含完整答案的存储库,包括文件夹结构和 yml 文件。您可以在 这个存储库 中看到它正在工作。
英文:
Azeem answered this. I'm posting this as an answer so that I can mark the question as solved.
With actions/checkout@v3, use fetch-depth: 0 to fetch all the branches.
Also add git config --global user.email "<myemail>" git config --global user.name "<my_username>".
This is a repo with the entire answer i.e folder structure and yml file. You can see it working in this repo
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论