Reputation: 879
I am fetching origin
like this:
git fetch origin
This will get all branches as master
and dev
.
Then I push it to another remote mirror-server
:
git push mirror-server master
Or, basically git push --all mirror-server
.
But this does not push my dev
branch to mirror-server
, only master
branch is pushed.
Error I get:
error: src refspec dev does not match any.
As shown I tried:
git push -u mirror-server dev
git push --all
I also tried switching curent branch and then push. No luck! Only one time I got something and it was this: Git basically put all files on dev
to master
and merge files…
Basically I need to pull changes from origin
and then push ALL branches to ALL other remotes.
Upvotes: 2
Views: 227
Reputation: 13577
This sequence of commands clones your GitHub repository (or any other repository if you change the URL) to ~/local-repos
, initializes an empty repository in ~/remote-repos.git
and pushes from ~/local-repos
to ~/remote-repos.git
all branches.
git clone 'https://github.com/nhnc-nginx/apache2nginx' ~/local-repos
git init --bare ~/remote-repos.git
cd ~/local-repos
git remote add mirror-server ~/remote-repos.git
git push --mirror mirror-server
Later you update tracking branches (and get new ones) in your ~/local-repos
with git fetch origin
executed inside ~/local-repos
. You can mirror everything to ~/remote-repos.git
again with git push --mirror mirror-server
. If you want to push a single branch (e.g. origin/gh-pages
), use git push mirror-server origin/gh-pages
.
Notice that https://github.com/nhnc-nginx/apache2nginx
remote is named origin
automatically. git fetch origin
fetches accessible objects from origin
repository and stores branches as tracking branches. Tracking branches are prefixed with the remote name (origin
in this case). If you perform git checkout gh-pages
and no gh-pages
branch exists, Git performs git branch --track gh-pages origin/gh-pages
before performing the checkout, which creates the gh-pages
branch with upstream set to origin/gh-pages
.
This was probably the source of the errors your Git reported. You fetched just origin/gh-pages
and tried to push non-existent gh-pages
branch. As part of checkout, gh-pages
was created, so push work then.
Also notice that you are creating a mirror of your local repository, not origin
. If you want to mirror your GitHub repository, you should execute git fetch origin
inside the just created empty mirror with git remote add origin 'https://github.com/nhnc-nginx/apache2nginx'
.
Upvotes: 2