How can I push all branches to a remote? If I have a project with two remotes, and I want to pull all remote branches from one of the sources and push it back to the second remote source. How can I do that without checking out all branches locally?
Short question
how can I push all of the remotes/origin* into origin2 remote?
git remote -v
# origin /project1 (fetch)
# origin /project1 (push)
# origin2 /project3 (fetch)
# origin2 /project3 (push)
git branch -a
# * master
# remotes/origin/HEAD -> origin/master
# remotes/origin/feature1
# remotes/origin/feature2
# remotes/origin/feature3
# remotes/origin/master
trying to use:
git push origin2 --all
# Everything up-to-date
Does not make the work, it says "Everything up-to-date" because nothing was locally modified.
Full example
(code is copy/paste executable, output is commented out with #):
suppose I create a project with just the master branch:
project1_dir=/project1
mkdir ${project1_dir}
cd ${project1_dir}
git init
touch file
git add file
git commit -m "file"
git log --graph --oneline --all
# * 46734b5 (HEAD -> master) file
and then I cloned, using:
project2_dir=/project2
project3_dir=/project3
git clone ${project1_dir} ${project2_dir}
git clone ${project1_dir} ${project3_dir}
and I set /project3 to be a remote source of /project2
cd ${project2_dir}
git remote add origin2 ${project3_dir}
so far we have:
cd /project1
git log --graph --oneline --all
# * 46734b5 (HEAD -> master) file
cd /project2
git log --graph --oneline --all
# * 46734b5 (HEAD -> master, origin/master, origin/HEAD) file
cd /project3
git log --graph --oneline --all
# * 46734b5 (HEAD -> master, origin/master, origin/HEAD) file
and then I create several branches on /project1
# simply create some branches
cd ${project1_dir}
features="feature1 feature2 feature3"
for feature in ${features}; do
echo Creating ${feature} branch
git branch ${feature} master
git checkout ${feature}
touch ${feature}
git add ${feature}
git commit -m "commit ${feature}"
done
and pull them to /project2:
cd ${project2_dir}
git fetch origin
git branch -a
# * master
# remotes/origin/HEAD -> origin/master
# remotes/origin/feature1
# remotes/origin/feature2
# remotes/origin/feature3
# remotes/origin/master
Then I try to push everything to /project3: (and here is where I would need the help)
git push origin2 --all
# Everything up-to-date
But that does not work:
cd ${project3_dir}
git branch -a
# * master
# remotes/origin/HEAD -> origin/master
# remotes/origin/master
here is the full script: https://pastebin.com/P7zs68Sc