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?
You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.
There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.
To pull changes from a specific branch in Git, first, launch the “Git Bash” on your system. Next, move to the Git local repository using the “cd” command. After that, execute the “$ git pull origin main” command to pull all changes from the origin and main branch and merge them in the local checked-out branch.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With