Here is a solution (form another question, originally presented by @DanielHarding) that you can put into your .gitconfig
and then invoke it with git partial-push origin branchname
(where origin is your desired remote)
[alias]
partial-push = "!sh -c 'REMOTE=$0;BRANCH=$1;BATCH_SIZE=100; if git show-ref --quiet --verify refs/remotes/$REMOTE/$BRANCH; then range=$REMOTE/$BRANCH..HEAD; else range=HEAD; fi; n=$(git log --first-parent --format=format:x $range | wc -l); echo "Have to push $n packages in range of $range"; for i in $(seq $n -$BATCH_SIZE 1); do h=$(git log --first-parent --reverse --format=format:%H --skip $i -n1); echo "Pushing $h..."; git push $REMOTE ${h}:refs/heads/$BRANCH; done; git push $REMOTE HEAD:refs/heads/$BRANCH'"
What it basically does is take the range of the commits it needs to push and then goes and pushes them one by one. It can take quite some time, but in the end it will do the job - automatically.
Here is above oneliner with some spacing for easier readability:
[alias]
partial-push = "!sh -c
'REMOTE=$0;BRANCH=$1;BATCH_SIZE=100;
if git show-ref --quiet --verify refs/remotes/$REMOTE/$BRANCH; then
range=$REMOTE/$BRANCH..HEAD;
else
range=HEAD;
fi;
n=$(git log --first-parent --format=format:x $range | wc -l);
echo "Have to push $n packages in range of $range";
for i in $(seq $n -$BATCH_SIZE 1); do
h=$(git log --first-parent --reverse --format=format:%H --skip $i -n1);
echo "Pushing $h...";
git push $REMOTE ${h}:refs/heads/$BRANCH;
done;
git push $REMOTE HEAD:refs/heads/$BRANCH'
"