简体   繁体   中英

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

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?

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)

I think you should give a try to --mirror option, ie 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.

While cloning an existing project into a new repo (using gitlab) i would suggest the following steps:

  1. Create a new directory into which you need to clone (git checkout) the project you want to clone as an independent project, such as "myproject".
  2. Use intelliJ to checkout from VCS and enter the url of the project to be cloned, for example git@gitlab.myproject.com:project/myproject.git
  3. Use the intelliJ terminal to execute the following commands:
  • "git remote -v" >>> this command should now show that git origin is connected to the original project repository, for example "origin git@gitlab.myproject.com:project/myproject.git"
  • "git remote set-url origin git@gitlab.myproject.com:independent-project/myproject.git" >>> through this command we set the origin to the newly created repository
  • "git remote -v" >>> executing this command should now indicate that the repository of this project is set to the newly created repository "origin git@gitlab.myproject.com:independent-project/myproject.git"
  • "git push -u origin --all" >>> with this command you will push all existing data from the project to the newly created repository.
  • "git push -u origin --tags" >>> if it is necessary to push all tags to the new repository, this command can also be executed. However, when cloning a project I assume you don't want this step.
  1. This completes the cloning of the existing project to the new repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM