10

I am using the following steps to duplicate all branches to the new-repository.

git clone --bare https://github.com/exampleuser/old-repository.git
# Make a bare clone of the repository

cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
# Mirror-push to the new repository

Now, I have added two new branches in old-repository.git and want to move only those 2 branches to new-repository.git

What git commands are required to perform it?

meallhour
  • 13,921
  • 21
  • 60
  • 117
  • I don't have an exact answer, but what is your motivation for wanting to move only two branches? – Tim Biegeleisen Mar 15 '18 at 02:25
  • I am moving from `old-repo` to `new-repo`. I have already moved all the branches to `new-repo` except 2 newly created branches in `old-repo` – meallhour Mar 15 '18 at 02:27
  • Perhaps you can try just pushing those new branches to the other repository, [see here](https://stackoverflow.com/questions/38118520/how-to-move-branch-from-one-repository-to-another-branch-of-different-repository). – Tim Biegeleisen Mar 15 '18 at 02:30

3 Answers3

19

You can add new_repo as a remote for old repo: this is more convenient for pushing:

cd old_repo
git remote add new /path/to/new/repo
git push new newBranch1
git push new newBranch2
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
6

Clone old branch

git clone --single-branch --branch branch_name github_repo_url

Tell git where your repo is:

git remote add mine your_repo_url

Then, push the branch to your repo with:

git push -u mine
meallhour
  • 13,921
  • 21
  • 60
  • 117
  • You don't have to clone your repo, you can directly point to the new one from the old one. – VonC Mar 15 '18 at 07:23
0

cd old_repo
git remote add new <New_git_repo_cloning_link>
git push new branchName