I have multiple local branches on my computer without remote.
I would like to push all my local branches that are not tracking a remote (I have multiple remote, e.g. origin
and upstream
) to the same remote (e.g. backup) url. For backuping purpose.
How could I do this?
Solution can be direct Git command or a bash script for listing branches without remote (I have multiple remote names) and iterating over them to push them to the same remote.
CodePudding user response:
Probably my question fits more for a bash script.
A combination of listing all local branches without remote iterating over them.
#!/bin/bash
while IFS= read -r aBranch ; do {
echo "Push ${aBranch} to backup";
git push backup "${aBranch}"
};
done < <(git branch --format '%(refname:short) %(upstream:short)' | awk '{if (!$2) print $1;}');
unset aBranch ;