Search code examples
gitrepositorygit-mergegit-fetchupstream-branch

Fetch and Merge into all Branches at once from Upstream Repository


I have a github fork, which I have cloned onto my computer. On the original project, I have opened many PRs, and each of them correspond to their own branch (I don't use master). From time to time, I occasionally run the following command:

git fetch upstream && git merge upstream/master --no-edit

(upstream is the original repository).

The command above works for updating the current branch that I am on. Is there a way to do the same for all my branches at once? Currently, to achieve the same behavior, I have to git checkout to all of the respective branches, and then do the sync, which I find quite tedious.

(I am quite new to git, so I would appreciate a good amount of explanation in an answer)


Solution

  • There is no way to do merge or rebase with non-current (not checked out) branch. Merge/rebase could have conflicts and the only way to resolve them is manually — hence the requirement to checkout the branch.

    You can fetch non-current branches if all branches can be fast-forwarded. The command:

    git fetch origin v1:v1 v2:v2
    

    fetches named branches and fast-forwards them. But if branch cannot be fast-forwarded the only way to merge is to check it out and merge.