I have two git repos: orginal(with master and some feature branches) and new(having just the master branch as it is created new). I want to copy everything from original (all the branches and history) to new.
I have followed this resource and so far am able to copy all the branches except the master branch to the new repo.
Here is what I have tried from original repo:
Created local copies of branches:
git branch -a * master remotes/origin/feature1 remotes/origin/feature2 remotes/origin/master git checkout -b feature1 origin/feature1 git checkout -b feature2 origin/feature2Added a new remote(new-origin):
git remote add new-origin <url-of-new-repo>Pushing all the branches to new remote:
git push --all new-origin
This has correctly created two feature branches on new repo, but didn't overwrite the master. This could happen since master exists for both the repos. Is there a way to overwrite the master branch from another repository?
CodePudding user response:
You are looking for the git branch command. Run this on the new repo after you fetched all branches from the original:
git branch --force master origin/master
This forces the local master branch to point to the same commit as the remote master branch.
