meallhour
meallhour

Reputation: 15571

How to copy only single branch from one git repo to another?

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?

Upvotes: 10

Views: 19076

Answers (3)

Manav Butani
Manav Butani

Reputation: 1

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

Upvotes: 0

meallhour
meallhour

Reputation: 15571

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

Upvotes: 6

VonC
VonC

Reputation: 1323115

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

Upvotes: 21

Related Questions