1

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?

Community
  • 1
  • 1

2 Answers2

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)

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
0

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.

Community
  • 1
  • 1
gzh
  • 3,291
  • 2
  • 18
  • 21
  • 1
    "Don’t use git push --mirror in repositories that weren’t cloned by --mirror as well. It’ll overwrite the remote repository with your local references (and your local branches)." This is not what i want. I guess i need to clone the repository with mirror repository again at a new location. – Kamal rajput Sep 12 '19 at 02:49