I recently forked a project and applied several fixes. I then created a pull request which was then accepted.
A few days later another change was made by another con
As a complement to this answer, I was looking for a way to update all remote branches of my cloned repo (origin) from upstream branches in one go. This is how I did it.
This assumes you have already configured an upstream remote pointing at the source repository (where origin was forked from) and have synced it with git fetch upstream
.
Then run:
for branch in $(git ls-remote --heads upstream|sed 's#^.*refs/heads/##'); do git push origin refs/remotes/upstream/$branch:refs/heads/$branch; done
The first part of this command lists all heads in the upstream remote repo and removes the SHA-1 followed by refs/heads/
branch name prefix.
Then for each of these branches, it pushes the local copy of the upstream remote tracking branch (refs/remotes/upstream/
on local side) directly to the remote branch on origin (refs/heads/
on remote side).
Any of these branch sync commands may fail for one of two reasons: either the upstream branch have been rewritten, or you have pushed commits on that branch to your fork. In the first case where you haven't committed anything to the branch on your fork it is safe to push forcefully (Add the -f switch; i.e. git push -f
in the command above). In the other case this is normal as your fork branch have diverged and you can't expect the sync command to work until your commits have been merged back into upstream.