问题
I have a need to clone an existing repo into a new one. Repositories are hosted on gitlab. For now i have created a new gitlab repository , and cloned the existing repo into the new one.
- mkdir newDirectory
- cd newDirectory
- git clone ssh://git@git.xyz.com:8888/Project/repo.git
- git remote rm origin ( to remove the origin frm existing repo)
- git remote add origin ssh://git@git.xyz.com:8888/Project/Newrepo.git
upto here everything worked fine. i checked for branches using command git branch -a - it showed all remote branches.
git push -u origin --all
( it resulted in pushing only master to the new git repo.I want to understand why all the branches are not cloned into the new directory.)
I want to push all the code from existing repo to new including branches, tags and everything.
What i am missing here?
回答1:
That was illustrated in "Move git repo with git clone --mirror and git push --mirror"
In your case, using git clone --mirror:
git clone --mirror ssh://git@git.xyz.com:8888/Project/repo.git
cd repo.git
git remote set-url origin ssh://git@git.xyz.com:8888/Project/Newrepo.git
git push --mirror
Note the use of git remote set-url (instead of remove/add)
回答2:
I think you should give a try to --mirror
option, i.e. run command git push --mirror origin
--mirror
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote..mirror is set.
来源:https://stackoverflow.com/questions/57898775/cloning-a-repo-into-a-new-project-and-then-push-it-to-gitlab