cloning a repo into a new project and then push it to gitlab

∥☆過路亽.° 提交于 2019-12-08 04:58:53

问题


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.

  1. mkdir newDirectory
  2. cd newDirectory
  3. git clone ssh://git@git.xyz.com:8888/Project/repo.git
  4. git remote rm origin ( to remove the origin frm existing repo)
  5. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!